race<B> method

Task<Either<A, B>> race<B>(
  1. Task<B> that
)

Implementation

Task<Either<A, B>> race<B>(Task<B> that) => Task(() async {
  final f = await Future.any([
    _run().then((value) => tuple2(0, value)),
    that._run().then((value) => tuple2(1, value)),
  ]);

  if(f is Tuple2<int, A> && f.value1 == 0) {
    return left(cast(f.value2));
  }
  else if(f is Tuple2<int, B> && f.value1 == 1) {
    return right(cast(f.value2));
  } else {
    throw TypeError();
  }
});