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

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

Issue 12316103: Introduce optimized Timer.run queue for immediate runs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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 | « no previous file | tests/isolate/timer_cancel_test.dart » ('j') | tests/standalone/standalone.status » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.async; 5 part of dart.async;
6 6
7 abstract class Timer { 7 abstract class Timer {
8 // Internal queue used to group Timer.run callbacks.
9 static Queue _queue = new Queue();
floitsch 2013/02/25 16:07:13 A list is good enough.
Anders Johnsen 2013/02/25 16:25:18 Done.
10
8 /** 11 /**
9 * Creates a new timer. 12 * Creates a new timer.
10 * 13 *
11 * The [callback] callback is invoked after the given [duration] 14 * The [callback] callback is invoked after the given [duration]
12 * (a [Duration]) has passed. A negative duration is treated similar to 15 * (a [Duration]) has passed. A negative duration is treated similar to
13 * a duration of 0. 16 * a duration of 0.
14 * 17 *
15 * If the [duration] is statically known to be 0, consider using [run]. 18 * If the [duration] is statically known to be 0, consider using [run].
16 * 19 *
17 * Frequently the [duration] is either a constant or computed as in the 20 * Frequently the [duration] is either a constant or computed as in the
(...skipping 23 matching lines...) Expand all
41 * 44 *
42 * *Deprecation warning*: this constructor used to take an [int] (the time 45 * *Deprecation warning*: this constructor used to take an [int] (the time
43 * in milliseconds). This has changed to a [Duration]. 46 * in milliseconds). This has changed to a [Duration].
44 */ 47 */
45 external factory Timer.repeating(var duration, 48 external factory Timer.repeating(var duration,
46 void callback(Timer timer)); 49 void callback(Timer timer));
47 50
48 /** 51 /**
49 * Runs the given [callback] asynchronously as soon as possible. 52 * Runs the given [callback] asynchronously as soon as possible.
50 * 53 *
51 * Returns a [Timer] that can be cancelled if the callback is not necessary 54 * Returns a [Timer] that can be cancelled if the callback is not necessary
floitsch 2013/02/25 16:07:13 Update comment.
Anders Johnsen 2013/06/11 12:14:31 Done.
52 * anymore. 55 * anymore.
53 */ 56 */
54 static Timer run(void callback()) { 57 static void run(void callback()) {
Søren Gjesse 2013/02/25 16:00:38 I don't see any problem with this not having any o
Anders Johnsen 2013/02/25 16:25:18 Done.
55 return new Timer(const Duration(), callback); 58 bool run = _queue.isEmpty;
59 _queue.addLast(callback);
60 if (run) {
61 new Timer(const Duration(), () {
floitsch 2013/02/25 16:07:13 Duration(milliseconds: 0)
Anders Johnsen 2013/02/25 16:25:18 Done.
62 var queue = _queue;
floitsch 2013/02/25 16:07:13 Use type.
Anders Johnsen 2013/02/25 16:25:18 Done.
63 _queue = new Queue();
Søren Gjesse 2013/02/25 16:00:38 Please make a comment to why you create a new queu
Anders Johnsen 2013/02/25 16:25:18 Done.
64 while (!queue.isEmpty) {
floitsch 2013/02/25 16:07:13 With the list: function runQueued(List queued, int
Anders Johnsen 2013/02/25 16:25:18 Didn't do exactly this, but close.
65 // Let it fall-through, as we already are at the top of the stack.
66 queue.removeFirst()();
67 }
68 });
69 }
56 } 70 }
57 71
58 /** 72 /**
59 * Cancels the timer. 73 * Cancels the timer.
60 */ 74 */
61 void cancel(); 75 void cancel();
62 } 76 }
OLDNEW
« no previous file with comments | « no previous file | tests/isolate/timer_cancel_test.dart » ('j') | tests/standalone/standalone.status » ('J')

Powered by Google App Engine
This is Rietveld 408576698