waitUntilReclaimed<T> method

  1. @protected
Future<T> waitUntilReclaimed<T>(
  1. Future<T> future
)

Disconnects the future from the the thread on this object if the object is reclaimed.

Implementation

@protected Future<T> waitUntilReclaimed<T>(Future<T> future) async
{
  try {
    T result = await future;
    if ( isNotReclaimed() ) {
      return result;
    }
  }
  catch (e) {
    if ( isNotReclaimed() ) {
      rethrow;
    }
  }

  // Reclaimed, so: Infinity future. Blocks forever.
  await ( new Completer<T>().future );

  throw new Exception("Never reached.");
}