Executes block if it's its turn, queues the block in the other case.
8432
def wait(i, &block)
      @order[i] = block
      return unless i == @current

      while order[@current]
        order.delete(@current).call
        @current += 1
      end
    end
1024868
private void executeAsyncCallRunnable(Runnable runnable, String callName, boolean blocking) {
		// make sure the executor is initialized. lock against concurrent calls to this function
		synchronized (this) {
			if (executionState != ExecutionState.RUNNING) {
				return;
			}

			// get ourselves a reference on the stack that cannot be concurrently modified
			BlockingCallMonitoringThreadPool executor = this.asyncCallDispatcher;
			if (executor == null) {
				// first time use, initialize
				checkState(userCodeClassLoader != null, "userCodeClassLoader must not be null");

				// Under normal execution, we expect that one thread will suffice, this is why we
				// keep the core threads to 1. In the case of a synchronous savepoint, we will block
				// the checkpointing thread, so we need an additional thread to execute the
				// notifyCheckpointComplete() callback. Finally, we aggressively purge (potentially)
				// idle thread so that we do not risk to have many idle thread on machines with multiple
				// tasks on them. Either way, only one of them can execute at a time due to the
				// checkpoint lock.

				executor = new BlockingCallMonitoringThreadPool(
						new DispatcherThreadFactory(
							TASK_THREADS_GROUP,
							"Async calls on " + taskNameWithSubtask,
							userCodeClassLoader));
				this.asyncCallDispatcher = executor;

				// double-check for execution state, and make sure we clean up after ourselves
				// if we created the dispatcher while the task was concurrently canceled
				if (executionState != ExecutionState.RUNNING) {
					executor.shutdown();
					asyncCallDispatcher = null;
					return;
				}
			}

			LOG.debug("Invoking async call {} on task {}", callName, taskNameWithSubtask);

			try {
				executor.submit(runnable, blocking);
			}
			catch (RejectedExecutionException e) {
				// may be that we are concurrently finished or canceled.
				// if not, report that something is fishy
				if (executionState == ExecutionState.RUNNING) {
					throw new RuntimeException("Async call with a " + (blocking ? "" : "non-") + "blocking call was rejected, even though the task is running.", e);
				}
			}
		}
	}
497220
def _process_queue(self):
        '''
        
        '''
        if len(self._queue):
            args, kwargs = self._queue.popleft()
            self.publish(*args, **kwargs)
1107271
@Override
  public void execute(Runnable runnable) {
    if (runnable == null) {
      throw new NullPointerException("runnable parameter is null");
    }

    if (!mWorkQueue.offer(runnable)) {
      throw new RejectedExecutionException(
          mName + " queue is full, size=" + mWorkQueue.size());
    }

    final int queueSize = mWorkQueue.size();
    final int maxSize = mMaxQueueSize.get();
    if ((queueSize > maxSize) && mMaxQueueSize.compareAndSet(maxSize, queueSize)) {
      FLog.v(TAG, "%s: max pending work in queue = %d", mName, queueSize);
    } // else, there was a race and another thread updated and logged the max queue size

    startWorkerIfNeeded();
  }
1131521
def queue_call(self, delay, callback, *args, **kwds):
    """"""
    if delay is None:
      self.current.append((callback, args, kwds))
      return
    if delay < 1e9:
      when = delay + self.clock.now()
    else:
      # Times over a billion seconds are assumed to be absolute.
      when = delay
    self.insort_event_right((when, callback, args, kwds))
448035
def handle(self):
        
        while True:
            # TODO: Queue.get() (and anything using thread.allocate_lock
            #       ignores signals :(  so timeout periodically to allow delivery
            try:
                callable = None # ensure no lingering references to past work while blocking
                callable = self._Q.get(True, 1.0)
            except Empty:
                continue  # retry on timeout
            try:
                if callable is self._stopit:
                    break
                callable()
            except:
                _log.exception("Error from WorkQueue")
            finally:
                self._Q.task_done()
273099
public function execute()
    {
        $queue = $this->container->getDelayedExecutionTaskQueue();
        if($queue->length() == 0){
            return;
        }
        ignore_user_abort(true);
        $queue->execute();
    }
38145
def block_call (context, &block)
      args = []
      block.parameters.each do |parameter|
        args << context[parameter[1]]
      end
      block.call(*args)
    end
427500
def _run_queued_callbacks(self):
        '''  '''
        for callback in self._queued_callbacks:
            try:
                callback()
            except Exception as ex:
                logger.error("Exception: %s" % str(ex))
1250113
InvocationCallback queuePoll() {
      InvocationCallback element;
      synchronized (this) {
         if (tail != head) {
            element = elements[head & mask];
            head++;
         } else {
            element = null;
            frozen = true;
         }
      }
      return element;
   }
1344375
function startBlock() {
            blockStack.push({
                let: { initialized: false, uninitialized: false },
                const: { initialized: false, uninitialized: false }
            });
        }
1071351
def run(&block)
      if block_given?
        set(:params, &block)
      end

      if post? and multipart?
        put_multipart_params_into_body
      else
        put_params_into_url
      end    
      
      request = RestClient::Request.execute(
         :method => http_method, 
         :url => url, 
         :headers => headers, 
         :payload => body
       )
       self.response = parse_response(request)
    end
335652
private synchronized void maybeRun() {
        if (inprogress==null && pending!=null) {
            base.submit(new Callable<Void>() {
                @Override
                public Void call() throws Exception {
                    synchronized (AtmostOneTaskExecutor.this) {
                        // everyone who submits after this should form a next batch
                        inprogress = pending;
                        pending = null;
                    }

                    try {
                        inprogress.set(task.call());
                    } catch (Throwable t) {
                        LOGGER.log(Level.WARNING, null, t);
                        inprogress.setException(t);
                    } finally {
                        synchronized (AtmostOneTaskExecutor.this) {
                            // if next one is pending, get that scheduled
                            inprogress = null;
                            maybeRun();
                        }
                    }
                    return null;
                }
            });
        }
    }
121570
def execute(*args, &task)
      if ensure_capacity?
        @scheduled_task_count += 1
        @queue << [args, task]
      else
        if @max_queue != 0 && @queue.length >= @max_queue
          handle_fallback(*args, &task)
        end
      end
      prune_pool
    end
521575
def on_trap(object_id, &block)
      raise ArgumentError, "a block must be provided" unless block
      @lock.synchronize { @oid_handler[ObjectId.new(object_id)] = block }
    end
79121
public static <T> BlockingQueue<T> newBlockingQueue(int capacity, boolean isLinked) {
		BlockingQueue<T> queue;
		if (isLinked) {
			queue = new LinkedBlockingDeque<>(capacity);
		} else {
			queue = new ArrayBlockingQueue<>(capacity);
		}
		return queue;
	}
1254120
def queue(action, *args)
      raise PoolClosed.new("Pool #{self} is currently closed") if pool_closed?
      raise ArgumentError.new('Expecting block') unless action.is_a?(Proc)
      @lock.synchronize do
        @queue << [action, args]
        create_thread
      end
    end