Dart DocumentationstagexlEventStreamSubscription<T>

EventStreamSubscription<T extends Event> class

class EventStreamSubscription<T extends Event> extends StreamSubscription<T> {

 int _priority = 0;
 int _pauseCount = 0;
 bool _canceled = false;
 bool _captures = false;

 EventStream<T> _eventStream;
 EventListener<T> _eventListener;

 EventStreamSubscription._internal(
     this._eventStream, this._eventListener, this._captures, this._priority);

 //-----------------------------------------------------------------------------------------------

 int get priority => _priority;

 bool get isPaused => _pauseCount > 0;
 bool get isCanceled => _canceled;
 bool get isCapturing => _captures;

 EventStream<T> get eventStream => _eventStream;
 EventListener<T> get eventListener => _eventListener;

 //-----------------------------------------------------------------------------------------------

 void onData(void handleData(T event)) {
   _eventListener = handleData;
 }

 void onError(void handleError(error)) {
   // This stream has no errors.
 }

 void onDone(void handleDone()) {
   // This stream is never done.
 }

 //-----------------------------------------------------------------------------------------------

 Future asFuture([var futureValue]) {
   // This stream is never done and has no errors.
   return new Completer().future;
 }

 //-----------------------------------------------------------------------------------------------

 Future cancel() {
   if (_canceled == false) {
     _eventStream._cancelSubscription(this);
   }
   return null;
 }

 void pause([Future resumeSignal]) {
   _pauseCount++;
   if (resumeSignal != null) {
     resumeSignal.whenComplete(resume);
   }
 }

 void resume()  {
   if (_pauseCount == 0) {
     throw new StateError("Subscription is not paused.");
   }
   _pauseCount--;
 }

}

Extends

StreamSubscription<T> > EventStreamSubscription<T>

Properties

final EventListener eventListener #

EventListener<T> get eventListener => _eventListener;

final EventStream<T> eventStream #

EventStream<T> get eventStream => _eventStream;

final bool isCanceled #

bool get isCanceled => _canceled;

final bool isCapturing #

bool get isCapturing => _captures;

final bool isPaused #

Returns true if the StreamSubscription is paused.

docs inherited from StreamSubscription<T>
bool get isPaused => _pauseCount > 0;

final int priority #

int get priority => _priority;

Methods

Future asFuture([futureValue]) #

Returns a future that handles the onDone and onError callbacks.

This method overwrites the existing onDone and onError callbacks with new ones that complete the returned future.

In case of an error the subscription will automatically cancel (even when it was listening with cancelOnError set to false).

In case of a done event the future completes with the given futureValue.

docs inherited from StreamSubscription<T>
Future asFuture([var futureValue]) {
 // This stream is never done and has no errors.
 return new Completer().future;
}

Future cancel() #

Cancels this subscription. It will no longer receive events.

If an event is currently firing, this unsubscription will only take effect after all subscribers have received the current event.

Returns a future if the cancel-operation is not completed synchronously. Otherwise returns null.

docs inherited from StreamSubscription<T>
Future cancel() {
 if (_canceled == false) {
   _eventStream._cancelSubscription(this);
 }
 return null;
}

void onData(void handleData(T event)) #

Set or override the data event handler of this subscription.

docs inherited from StreamSubscription<T>
void onData(void handleData(T event)) {
 _eventListener = handleData;
}

void onDone(void handleDone()) #

Set or override the done event handler of this subscription.

docs inherited from StreamSubscription<T>
void onDone(void handleDone()) {
 // This stream is never done.
}

void onError(void handleError(error)) #

Set or override the error event handler of this subscription.

This method overrides the handler that has been set at the invocation of Stream.listen.

docs inherited from StreamSubscription<T>
void onError(void handleError(error)) {
 // This stream has no errors.
}

void pause([Future resumeSignal]) #

Request that the stream pauses events until further notice.

If resumeSignal is provided, the stream will undo the pause when the future completes. If the future completes with an error, it will not be handled!

A call to resume will also undo a pause.

If the subscription is paused more than once, an equal number of resumes must be performed to resume the stream.

Currently DOM streams silently drop events when the stream is paused. This is a bug and will be fixed.

docs inherited from StreamSubscription<T>
void pause([Future resumeSignal]) {
 _pauseCount++;
 if (resumeSignal != null) {
   resumeSignal.whenComplete(resume);
 }
}

void resume() #

Resume after a pause.

docs inherited from StreamSubscription<T>
void resume()  {
 if (_pauseCount == 0) {
   throw new StateError("Subscription is not paused.");
 }
 _pauseCount--;
}