register<T> method

Future<T> register<T>(
  1. CancellationToken cancelToken,
  2. Future<T> future
)

Implementation

static Future<T> register<T>(
    CancellationToken cancelToken, Future<T> future) {
  if (cancelToken != null && !cancelToken.isCanceled) {
    Completer completer = new Completer();
    cancelToken._addCompleter(completer);
    return Future.any([completer.future, future]).then<T>((result) {
      cancelToken._removeCompleter(completer);
      return result;
    }).catchError((error) {
      cancelToken._removeCompleter(completer);
      throw error;
    });
  } else {
    return future;
  }
}