Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: sdk/lib/async/signal.dart

Issue 11794043: Remove Signal class and use Future/.whenComplete instead. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Comment updated. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/async/future_impl.dart ('k') | sdk/lib/async/stream.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 // part of dart.async;
6
7 /**
8 * A basic asynchronous notification.
9 *
10 * *DEPRECATED*
11 *
12 * This class is scheduled for removal. Please don't use.
13 */
14 abstract class Signal {
15 factory Signal.delayed(int milliseconds) {
16 var completer = new SignalCompleter();
17 new Timer(milliseconds, (_) => completer.complete());
18 return completer.signal;
19 }
20 /**
21 * The [onComplete] handler is called when the signal completes.
22 *
23 * If the signal is already complete, the [onComplete] handler is called
24 * as soon as possible, but no sooner than the next time an event is fired.
25 */
26 void then(void onComplete());
27 }
28
29 typedef _SignalCompleteHandler();
30
31 /**
32 * Simple [Signal] controller that creates a [Signal] and allows completing it.
33 *
34 * *DEPRECATED*
35 *
36 * This class is scheduled for removal. Please don't use.
37 */
38 class SignalCompleter {
39 final Signal signal;
40 SignalCompleter() : signal = new _SignalImpl();
41 void complete() {
42 _SignalImpl mySignal = signal;
43 mySignal._complete();
44 }
45 }
46
47 /**
48 * Simple Signal implementation receiving its completion from a
49 * [SignalCompleter].
50 */
51 class _SignalImpl implements Signal {
52 /** Single-linked list of "done" event handlers to notify. */
53 _SignalListener _listeners = null;
54
55 /** Whether the signal is already completed. */
56 bool _isComplete = false;
57
58 void then(void onComplete()) {
59 _listeners = new _SignalListener(_listeners, onComplete);
60 if (_isComplete) {
61 // Schedule the done events as soon as the event queue is ready.
62 new Timer(0, (Timer timer) { _sendDone(); });
63 }
64 }
65
66 /**
67 * Complete the signal.
68 *
69 * This immediately notifies all listeners on the signal.
70 */
71 void _complete() {
72 assert(!_isComplete); // Only complete once.
73 _isComplete = true;
74 _sendDone();
75 }
76
77 /**
78 * Notify all listeners.
79 */
80 void _sendDone() {
81 while (_listeners != null) {
82 _DoneHandler onDone = _listeners.listener;
83 _listeners = _listeners.next;
84 try {
85 onDone();
86 } catch (e, s) {
87 new AsyncError(e, s).throwDelayed();
88 }
89 }
90 }
91 }
92
93 /** Single-linked list element of the listeners on a [_SignalImpl]. */
94 class _SignalListener {
95 _SignalListener next;
96 _SignalCompleteHandler listener;
97 _SignalListener(this.next, this.listener);
98 }
OLDNEW
« no previous file with comments | « sdk/lib/async/future_impl.dart ('k') | sdk/lib/async/stream.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698