Perform block after given period
 @param time [Fixnum]
 @param block [Proc]
 @yield if there is no block given it yield without param.
 @return [Concurrent::ScheduledTask]
17174
def perform_after(time, block=nil)
      task = Concurrent::ScheduledTask.new(time) do
        block = ->(){ yield } unless block
        self.async.perform_now block
      end
      task.execute
      task
    end
619101
protected Block visitBlock(Block block) {
        if (block == null) {
            return null;
        }

        Statement stmt = (Statement)block.accept(this);

        if (stmt instanceof Block) {
            return (Block)stmt;
        }
        else if (stmt != null) {
            return new Block(stmt);
        }
        else {
            return new Block(block.getSourceInfo());
        }
    }
365116
def if_state(*expected_states)
      mutex.lock
      raise ArgumentError, 'no block given' unless block_given?

      if expected_states.include? @state
        yield
      else
        false
      end
    ensure
      mutex.unlock
    end
700864
def advance(time)
      yes, no = @stack.partition { |rule| rule.include?(time) }

      if no.empty?
        yes.all? { |rule| rule.advance!(time) } or return false
        puts time if ENV["DEBUG"]
        yield time if block_given?
        true
      else
        no.any? { |rule| rule.continue?(time) }
      end
    end
115336
def _highlighBlocks(self, fromBlock, atLeastUntilBlock, timeout):
        endTime = time.time() + timeout

        block = fromBlock
        lineData = self._lineData(block.previous())

        while block.isValid() and block != atLeastUntilBlock:
            if time.time() >= endTime:  # time is over, schedule parsing later and release event loop
                self._pendingBlockNumber = block.blockNumber()
                self._pendingAtLeastUntilBlockNumber = atLeastUntilBlock.blockNumber()
                self._globalTimer.scheduleCallback(self._onContinueHighlighting)
                return

            contextStack = lineData[0] if lineData is not None else None
            if block.length() < 4096:
                lineData, highlightedSegments = self._syntax.highlightBlock(block.text(), contextStack)
            else:
                """Parser freezes for a long time, if line is too long
                invalid parsing results are still better, than freeze
                """
                lineData, highlightedSegments = None, []
            if lineData is not None:
                block.setUserData(_TextBlockUserData(lineData))
            else:
                block.setUserData(None)

            self._applyHighlightedSegments(block, highlightedSegments)
            block = block.next()

        # reached atLeastUntilBlock, now parse next only while data changed
        prevLineData = self._lineData(block)
        while block.isValid():
            if time.time() >= endTime:  # time is over, schedule parsing later and release event loop
                self._pendingBlockNumber = block.blockNumber()
                self._pendingAtLeastUntilBlockNumber = atLeastUntilBlock.blockNumber()
                self._globalTimer.scheduleCallback(self._onContinueHighlighting)
                return
            contextStack = lineData[0] if lineData is not None else None
            lineData, highlightedSegments = self._syntax.highlightBlock(block.text(), contextStack)
            if lineData is not None:
                block.setUserData(_TextBlockUserData(lineData))
            else:
                block.setUserData(None)

            self._applyHighlightedSegments(block, highlightedSegments)
            if prevLineData == lineData:
                break

            block = block.next()
            prevLineData = self._lineData(block)

        # sucessfully finished, reset pending tasks
        self._pendingBlockNumber = None
        self._pendingAtLeastUntilBlockNumber = None

        
        documentLayout = self._textEdit.document().documentLayout()
        documentLayout.documentSizeChanged.emit(documentLayout.documentSize())
1114796
def run_evaluate(self, block: TimeAggregate) -> bool:
        
        if self._anchor.evaluate_anchor(block, self._evaluation_context):

            try:
                self.run_reset()
                self._evaluation_context.global_add('anchor', block)
                self._evaluate()
                self._anchor.add_condition_met()
                return True
            finally:
                self._evaluation_context.global_remove('anchor')

        return False
1147119
public void resolveBlock (SceneBlock block, boolean hipri)
    {
        log.debug("Queueing block for resolution", "block", block, "hipri", hipri);
        if (hipri) {
            _queue.prepend(block);
        } else {
            _queue.append(block);
        }
    }
8432
def wait(i, &block)
      @order[i] = block
      return unless i == @current

      while order[@current]
        order.delete(@current).call
        @current += 1
      end
    end
618435
def call_block(block,stdout,stderr,exitstatus)
      # blocks that take no arguments have arity -1.  Or 0.  Ugh.
      if block.arity > 0
        case block.arity
        when 1 
          block.call(stdout)
        when 2
          block.call(stdout,stderr)
        else
          # Let it fail for lambdas
          block.call(stdout,stderr,exitstatus)
        end
      else
        block.call
      end
    end
183052
def post_process(*shaders)
      raise ArgumentError, "Block required" unless block_given?
      raise TypeError, "Can only process with Shaders" unless shaders.all? {|s| s.is_a? Ashton::Shader }

      # In case no shaders are passed, just run the contents of the block.
      unless shaders.size > 0
        yield
        return
      end

      buffer1 = primary_buffer
      buffer1.clear

      # Allow user to draw into a buffer, rather than the window.
      buffer1.render do
        yield
      end

      if shaders.size > 1
        buffer2 = secondary_buffer # Don't need to clear, since we will :replace.

        # Draw into alternating buffers, applying each shader in turn.
        shaders[0...-1].each do |shader|
          buffer1, buffer2 = buffer2, buffer1
          buffer1.render do
            buffer2.draw 0, 0, nil, shader: shader, mode: :replace
          end
        end
      end

      # Draw the buffer directly onto the window, utilising the (last) shader.
      buffer1.draw 0, 0, nil, shader: shaders.last
    end
916848
def _scheduling_block_ids(num_blocks, start_id, project):
    """"""
    for i in range(num_blocks):
        _root = '{}-{}'.format(strftime("%Y%m%d", gmtime()), project)
        yield '{}-sb{:03d}'.format(_root, i + start_id), \
              '{}-sbi{:03d}'.format(_root, i + start_id)
848052
def from(time, &block)
      time = time.to_time if time.is_a?(::Date)
      method, args = @method_chain.pop if block_given?
      if !method.nil?
        time.until(self).send(method, *args, &block)
      else
        time.until(self)
      end
    end
103938
def on_complete(&block)
      on do |_, value, reason|
        block.call(reason == nil, value, reason)
      end
    end
270987
def reconfigure(&block)
      mutex.lock
      raise ArgumentError.new('no block given') unless block_given?
      unless @computing
        @task = block
        true
      else
        false
      end
    ensure
      mutex.unlock
    end
810413
public long execute(Consumer<StatusContext> block) {
        long numUnitsProcessed = 0L;


        // Keep track of average time used per unig (average time per unit)
        MovingAverage averageTPU = new MovingAverage();

        // Average imposed delay
        MovingAverage averageDelay = new MovingAverage();

        StatusContext statusContext = new StatusContext();

        while (numUnitsProcessed < maxUnitsProcessedInSequence) {

            statusContext.reset();

            synchronized (semaphore) {
                if (shutdownRequests.size() > 0) {
                    String info = "Shutting down processing due to request: " + shutdownRequests.remove(0);
                    out.println(info);
                    inform(numUnitsProcessed, averageTPU, averageDelay);

                    return numUnitsProcessed;
                }
            }

            long startTime = System.currentTimeMillis();
            block.accept(statusContext);
            long endTime = System.currentTimeMillis();

            if (statusContext.isFinished() || (!statusContext.getStatus() && --numberOfErrorsAccepted < 0)) {
                return numUnitsProcessed;
            }

            averageTPU.update(endTime - startTime);
            ++numUnitsProcessed;

            // Possibly delay processing so that we do not process more than 'maxUnitsProcessedPerMinute' - on average
            final double slotTime = (60000) / maxUnitsProcessedPerMinute;   // milliseconds
            double averageProcessingTime = averageTPU.getAverage(); // milliseconds
            long waitTime = (long) (slotTime - Math.ceil(averageProcessingTime));  // milliseconds

            if (waitTime > 0) {
                averageDelay.update(waitTime);
                synchronized (semaphore) {
                    try {
                        semaphore.wait(waitTime);
                    } catch (InterruptedException ignore) {}
                }
            }
            synchronized (semaphore) {
                if (shutdownRequests.size() > 0) {
                    String info = "Shutting down processing due to request: " + shutdownRequests.remove(0);
                    out.println(info);
                    inform(numUnitsProcessed, averageTPU, averageDelay);

                    return numUnitsProcessed;
                }
            }

            if ((numUnitsProcessed % INFORM_EACH_N_UNITS) == 0) {
                // Inform each N:th time through
                inform(numUnitsProcessed, averageTPU, averageDelay);
            }
        }
        if ((numUnitsProcessed % INFORM_EACH_N_UNITS) != 0) {
            // Only inform if we have not just done that :)
            inform(numUnitsProcessed, averageTPU, averageDelay);
        }
        return numUnitsProcessed;
    }
38145
def block_call (context, &block)
      args = []
      block.parameters.each do |parameter|
        args << context[parameter[1]]
      end
      block.call(*args)
    end
737757
function run(scheduled) {
        pumping = true;
        schedulerProfilerMark("timeslice", "StartTM");
        var didWork;
        var ranJobSuccessfully = true;
        var current;
        var lastLoggedPriority;
        var timesliceExhausted = false;
        var yieldForPriorityBoundary = false;

        // Reset per-run state
        //
        immediateYield = false;

        try {
            var start = now();
            var end = start + TIME_SLICE;

            // Yielding policy
            //
            // @TODO, should we have a different scheduler policy when the debugger is attached. Today if you
            //  break in user code we will generally yield immediately after that job due to the fact that any
            //  breakpoint will take longer than TIME_SLICE to process.
            //

            var shouldYield = function () {
                timesliceExhausted = false;
                if (immediateYield) { return true; }
                if (wwaTaskScheduledAtPriorityHigherThan(toWwaPriority(highWaterMark))) { return true; }
                if (!!drainQueue.length) { return false; }
                if (now() > end) {
                    timesliceExhausted = true;
                    return true;
                }
                return false;
            };

            // Run until we run out of jobs or decide it is time to yield
            //
            while (highWaterMark >= Priority.min && !shouldYield() && !yieldForPriorityBoundary) {

                didWork = false;
                current = markerFromPriority(highWaterMark)._nextJob;
                do {
                    // Record the priority currently being pumped
                    //
                    pumpingPriority = current.priority;

                    if (current instanceof JobNode) {
                        if (lastLoggedPriority !== current.priority) {
                            if (+lastLoggedPriority === lastLoggedPriority) {
                                schedulerProfilerMark("priority", "StopTM", markerFromPriority(lastLoggedPriority).name);
                            }
                            schedulerProfilerMark("priority", "StartTM", markerFromPriority(current.priority).name);
                            lastLoggedPriority = current.priority;
                        }

                        // Important that we update this state before calling execute because the
                        //  job may throw an exception and we don't want to stall the queue.
                        //
                        didWork = true;
                        ranJobSuccessfully = false;
                        runningJob = current;
                        jobProfilerMark(runningJob, "job-running", "StartTM", markerFromPriority(pumpingPriority).name);
                        current._execute(shouldYield);
                        jobProfilerMark(runningJob, "job-running", "StopTM", markerFromPriority(pumpingPriority).name);
                        runningJob = null;
                        ranJobSuccessfully = true;
                    } else {
                        // As we pass marker nodes update our high water mark. It's important to do
                        //  this before notifying drain listeners because they may schedule new jobs
                        //  which will affect the highWaterMark.
                        //
                        var wwaPrevHighWaterMark = toWwaPriority(highWaterMark);
                        highWaterMark = current.priority;

                        didWork = notifyDrainListeners();

                        var wwaHighWaterMark = toWwaPriority(highWaterMark);
                        if (isHigherWwaPriority(wwaPrevHighWaterMark, wwaHighWaterMark) &&
                                (!usingWwaScheduler || MSApp.isTaskScheduledAtPriorityOrHigher(wwaHighWaterMark))) {
                            // Timeslice is moving to a lower WWA priority and the host
                            //  has equally or more important work to do. Time to yield.
                            //
                            yieldForPriorityBoundary = true;
                        }
                    }

                    current = current._nextJob;

                    // When didWork is true we exit the loop because:
                    //  - We've called into user code which may have modified the
                    //    scheduler's queue. We need to restart at the high water mark.
                    //  - We need to check if it's time for the scheduler to yield.
                    //
                } while (current && !didWork && !yieldForPriorityBoundary && !wwaTaskScheduledAtPriorityHigherThan(toWwaPriority(highWaterMark)));

                // Reset per-item state
                //
                immediateYield = false;

            }

        } finally {
            runningJob = null;

            // If a job was started and did not run to completion due to an exception
            //  we should transition it to a terminal state.
            //
            if (!ranJobSuccessfully) {
                jobProfilerMark(current, "job-error", "info");
                jobProfilerMark(current, "job-running", "StopTM", markerFromPriority(pumpingPriority).name);
                current.cancel();
            }

            if (+lastLoggedPriority === lastLoggedPriority) {
                schedulerProfilerMark("priority", "StopTM", markerFromPriority(lastLoggedPriority).name);
            }
            // Update high water mark to be the priority of the highest priority job.
            //
            var foundAJob = false;
            while (highWaterMark >= Priority.min && !foundAJob) {

                didWork = false;
                current = markerFromPriority(highWaterMark)._nextJob;
                do {

                    if (current instanceof JobNode) {
                        // We found a job. High water mark is now set to the priority
                        //  of this job.
                        //
                        foundAJob = true;
                    } else {
                        // As we pass marker nodes update our high water mark. It's important to do
                        //  this before notifying drain listeners because they may schedule new jobs
                        //  which will affect the highWaterMark.
                        //
                        highWaterMark = current.priority;

                        didWork = notifyDrainListeners();
                    }

                    current = current._nextJob;

                    // When didWork is true we exit the loop because:
                    //  - We've called into user code which may have modified the
                    //    scheduler's queue. We need to restart at the high water mark.
                    //
                } while (current && !didWork && !foundAJob);
            }

            var reasonForYielding;
            if (!ranJobSuccessfully) {
                reasonForYielding = "job error";
            } else if (timesliceExhausted) {
                reasonForYielding = "timeslice exhausted";
            } else if (highWaterMark < Priority.min) {
                reasonForYielding = "jobs exhausted";
            } else if (yieldForPriorityBoundary) {
                reasonForYielding = "reached WWA priority boundary";
            } else {
                reasonForYielding = "WWA host work";
            }

            // If this was a scheduled call to the pump, then the pump is no longer
            //  scheduled to be called and we should clear its scheduled priority.
            //
            if (scheduled) {
                scheduledWwaPriority = null;
            }

            // If the high water mark has not reached the end of the queue then
            //  we re-queue in order to see if there are more jobs to run.
            //
            pumping = false;
            if (highWaterMark >= Priority.min) {
                startRunning();
            }
            schedulerProfilerMark("yielding", "info", reasonForYielding);
            schedulerProfilerMark("timeslice", "StopTM");
        }
    }