An async result aggregator that combines all the results
       This gets executed in unsync.loop and unsync.thread
161771
async def result_processor(tasks):
    """"""
    output = {}
    for task in tasks:
        num, res = await task
        output[num] = res
    return output
1331999
def result(self):
        
        # Send None to all threads to cleanly stop them
        for _ in range(self.num_threads):
            self.tasks_queue.put(None)
        # Wait for completion of all the tasks in the queue
        self.tasks_queue.join()
        # Check if one of the thread raised an exception, if yes
        # raise it here in the function
        if not self.exceptions_queue.empty():
            raise self.exceptions_queue.get()
        return self.results_queue
897360
def background_reader(stream, loop: asyncio.AbstractEventLoop, callback):
    

    for line in iter(stream.readline, b''):
        loop.call_soon_threadsafe(loop.create_task, callback(line))
790301
private void processResult(Executor executor) {
        // Process the result, one entry at a time, until one of the stopping conditions occurs.
        AtomicBoolean shouldContinue = new AtomicBoolean(true);
        Futures
                .loop(
                        () -> !this.closed.get() && shouldContinue.get(),
                        () -> {
                            CompletableFuture<ReadResultEntry> resultEntryFuture = fetchNextEntry();
                            shouldContinue.set(resultEntryFuture != null);
                            return resultEntryFuture != null ? resultEntryFuture : CompletableFuture.completedFuture(null);
                        },
                        resultEntry -> {
                            if (resultEntry != null) {
                                shouldContinue.set(this.entryHandler.processEntry(resultEntry));
                            }
                        },
                        executor)
                .whenComplete((r, ex) -> close(ex)); // Make sure always close the result processor when done (with our without failures).
    }
1032807
synchronized void result(@Nullable T res) {
        if (isFinished) {
            throw new RuntimeException("Promise " + this + " already completed!");
        }
        isFinished = true;
        result = res;
        deliverResult();
    }
902954
def _run_sync(self, method: Callable, *args, **kwargs) -> Any:
        
        if self.loop.is_running():
            raise RuntimeError("Event loop is already running.")

        if not self.is_connected:
            self.loop.run_until_complete(self.connect())

        task = asyncio.Task(method(*args, **kwargs), loop=self.loop)
        result = self.loop.run_until_complete(task)

        self.loop.run_until_complete(self.quit())

        return result
1016805
def get_results(self, **kwargs):
        
        # Check whether the process completed.
        if self.returncode is None:
            raise self.Error("return code is None, you should call wait, communicate or poll")

        if self.status is None or self.status < self.S_DONE:
            raise self.Error("Task is not completed")

        return self.Results.from_node(self)
1290363
function resultsCallback() {
    
    var args = slice.call(arguments, 0);
    var err = args.shift();
        
    if (err) {
      if (config.interrupt === true) {
        errors.push(err);
        results.push(null);
        callback.call(self, errors, results);
        return;
      } else {
         errored = true; 
         args = null;
      }
    } else if (args.length === 0) {
      args = 'OK';
    } else if (args.length == 1) {
      args = args[0];
    }
    
    errors.push(err);
    results.push(args);
    
    self.emit('each', err, counter, args);
    
    if (config.parallel) {
      
      // Parallel

      if (++counter == stack.length) {
        self.promise.emit('finished');
      }

    } else {
      
      // Sequential
      
      if (++counter == stack.length) {
        var preparedArgs = setInitialState(true); // Reset state, then return
        self.emit('post_exec');
        callback.apply(self, preparedArgs);
      } else {
        var next = stack[counter];
        context[next.caller].apply(context, next.args);
      }

    }

  }
412311
function injectAsync(asyncList, content, usedSync, filePath) {
        if (asyncList.length === 0) {
            return content.replace(settings.resourceMapTag, '');
        }
        var subpath = settings.pageSubPath.replace('${index}', asyncCount).replace('{$hash}', fis.util.md5(filePath));
        var file = genAsyncMap(asyncList, subpath, usedSync, settings.codeGen);
        asyncCount++;
        return injectAsyncWithMap(content, file);
    }
1192090
async def _stream_raw_result(self, res):
        '''  '''
        async with res.context as response:
            response.raise_for_status()
            async for out in response.content.iter_chunked(1):
                yield out.decode()
727957
function handleArrayResult(m, workerIdx) {
	var job = jobs[m.context.jobID],
		partition = m.context.partition,
		subResult = m.result,
		result = [],
		i;
	
	job.result[partition] = subResult;

	// Increase callback count.
	job.cbCount++;
	
	// When all workers are finished return result
	if(job.cbCount === workers.length) {
		for (i = 0; i < job.result.length; i++) {
			result = result.concat(job.result[i]);
		};
		
		// Cle
		job.cb(null, result);
	}

	// Worker is finished.
	workerJobCount[workerIdx]--;
	dispatchWorkItems();
}
430717
def asynciotask(
    func: None = None,
    *,
    loop_getter: typing.Union[
        typing.Callable[..., asyncio.AbstractEventLoop], asyncio.AbstractEventLoop
    ] = asyncio.get_event_loop,
    loop_getter_need_context: bool = False,
) -> AsyncIOTask:
    """"""
805399
private void afterDataFsync(Result<Boolean> result,
                              int position,
                              FsyncType fsyncType,
                              ArrayList<SegmentFsyncCallback> listeners)
  {
    try {
      completeIndex(position);
      
      Result<Boolean> cont = result.then((v,r)->
        afterIndexFsync(r, fsyncType, listeners));

      if (fsyncType.isSchedule()) {
        _sOut.fsyncSchedule(cont);
      }
      else {
        _sOut.fsync(cont);
        
      }
    } catch (Throwable e) {
      result.fail(e);
    }
  }
876652
def results(self):
        """"""
        tt = None
        for i, tf in enumerate(self[:-1]):
            tt = self[i+1]
            q = Queue(tf.qsize)
            tf.set_out(q, tt.workers)
            tt.set_in(q, tf.workers)

        if tt is None: # we have only one pool
            tt = self[0]
        q = Queue(tt.qsize)
        err_q = Queue()
        tt.set_out(q, 1)

        for t in self:
            t.set_err(err_q)
            t._start()

        for item in iterqueue(q, tt.workers):
            yield item

        errors = list(iterqueue(err_q, sum(t.workers for t in self)))

        for t in self:
            t._join()

        if len(errors) > 0:
            task_name, ex = errors[0]
            if len(errors) == 1:
                msg = 'The task "%s" raised %s' % (task_name, repr(ex),)
            else:
                msg = '%d tasks raised an exeption. First error reported on task "%s": %s' % (len(errors), task_name, repr(ex))

            raise TaskException(msg)
1308742
@Private
  @Override
  public void aggregationCompleted(final List<Integer> taskletIds, final TOutput result) {
    try {
      completedTasklets(result, taskletIds);
    } catch (final InterruptedException e) {
      throw new RuntimeException(e);
    }
  }
805289
def fetch_data_async(blob, start_index, end_index, **options):
  """"""
  if isinstance(blob, BlobInfo):
    blob = blob.key()
  rpc = blobstore.create_rpc(**options)
  rpc = blobstore.fetch_data_async(blob, start_index, end_index, rpc=rpc)
  result = yield rpc
  raise tasklets.Return(result)
1336736
public static <R> OnSubscribe<R> fromRunnable(final Runnable run, final R result) {
        return new InvokeAsync<R>(new Func0<R>() {
            @Override
            public R call() {
                run.run();
                return result;
            }
        });
    }