eu.toolchain.async.AsyncFuture.onFinished()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(2.9k)|赞(0)|评价(0)|浏览(95)

本文整理了Java中eu.toolchain.async.AsyncFuture.onFinished()方法的一些代码示例,展示了AsyncFuture.onFinished()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AsyncFuture.onFinished()方法的具体详情如下:
包路径:eu.toolchain.async.AsyncFuture
类名称:AsyncFuture
方法名:onFinished

AsyncFuture.onFinished介绍

[英]Register a listener to be called when this future finishes for any reason.
[中]注册一个侦听器,以便在将来由于任何原因结束时调用。

代码示例

代码示例来源:origin: eu.toolchain.async/tiny-async-core

@Override
  public AsyncFuture<Void> transform(Void result) throws Exception {
    while (true) {
      final Managed<T> old = current.get();
      // we are stopping
      // block old from successfully stopping until this one has been cleaned up.
      if (old == null) {
        return next.stop().onFinished(b.releasing());
      }
      if (!current.compareAndSet(old, next)) {
        continue;
      }
      // swap successful, now we can now safely release old.
      b.release();
      // stopping old.
      return old.stop();
    }
  }
});

代码示例来源:origin: com.spotify.ffwd/ffwd-api

futures.add(sink
    .sendEvents(batch.events)
    .onFinished(() -> batchingStatistics.reportSentEvents(batch.events.size())));
  futures.add(sink
    .sendMetrics(batch.metrics)
    .onFinished(() -> batchingStatistics.reportSentMetrics(batch.metrics.size())));
  futures.add(sink
    .sendBatches(batch.batches)
    .onFinished(() -> batchingStatistics.reportSentBatches(batch.batches.size(),
      batch.size())));
return async.collectAndDiscard(futures).onFinished(writeMonitor).onFinished(() -> {
  batchingStatistics.reportQueueSizeDec(batch.size());
  batchingStatistics.reportInternalBatchWrite(batch.size());

代码示例来源:origin: spotify/ffwd

futures.add(sink
    .sendEvents(batch.events)
    .onFinished(() -> batchingStatistics.reportSentEvents(batch.events.size())));
  futures.add(sink
    .sendMetrics(batch.metrics)
    .onFinished(() -> batchingStatistics.reportSentMetrics(batch.metrics.size())));
  futures.add(sink
    .sendBatches(batch.batches)
    .onFinished(() -> batchingStatistics.reportSentBatches(batch.batches.size(),
      batch.size())));
return async.collectAndDiscard(futures).onFinished(writeMonitor).onFinished(() -> {
  batchingStatistics.reportQueueSizeDec(batch.size());
  batchingStatistics.reportInternalBatchWrite(batch.size());

代码示例来源:origin: eu.toolchain.async/tiny-async-core

@Override
public <R> AsyncFuture<R> doto(final ManagedAction<T, R> action) {
  final Borrowed<T> b = borrow();
  if (!b.isValid()) {
    return async.cancelled();
  }
  final T reference = b.get();
  final AsyncFuture<R> f;
  try {
    f = action.action(reference);
  } catch (Exception e) {
    b.release();
    return async.failed(e);
  }
  return f.onFinished(b.releasing());
}

代码示例来源:origin: eu.toolchain.async/tiny-async-core

@Override
public <R> AsyncFuture<R> doto(final ManagedAction<T, R> action) {
  // pre-emptively increase the number of leases in order to prevent the underlying object
  // (if valid) to be
  // allocated.
  final Borrowed<T> b = borrow();
  if (!b.isValid()) {
    return async.cancelled();
  }
  final T reference = b.get();
  final AsyncFuture<R> f;
  try {
    f = action.action(reference);
  } catch (Exception e) {
    b.release();
    return async.failed(e);
  }
  return f.onFinished(b.releasing());
}

相关文章