Chromium Code Reviews| Index: sdk/lib/async/timer.dart |
| diff --git a/sdk/lib/async/timer.dart b/sdk/lib/async/timer.dart |
| index 39fe4c2df6202e1500940372e47d2583085f16b8..7df5e6cbdc1840825a121196643d1e7bc448e019 100644 |
| --- a/sdk/lib/async/timer.dart |
| +++ b/sdk/lib/async/timer.dart |
| @@ -5,6 +5,9 @@ |
| part of dart.async; |
| abstract class Timer { |
| + // Internal queue used to group Timer.run callbacks. |
| + 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.
|
| + |
| /** |
| * Creates a new timer. |
| * |
| @@ -51,8 +54,19 @@ abstract class Timer { |
| * 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.
|
| * anymore. |
| */ |
| - static Timer run(void callback()) { |
| - return new Timer(const Duration(), callback); |
| + 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.
|
| + bool run = _queue.isEmpty; |
| + _queue.addLast(callback); |
| + if (run) { |
| + new Timer(const Duration(), () { |
|
floitsch
2013/02/25 16:07:13
Duration(milliseconds: 0)
Anders Johnsen
2013/02/25 16:25:18
Done.
|
| + var queue = _queue; |
|
floitsch
2013/02/25 16:07:13
Use type.
Anders Johnsen
2013/02/25 16:25:18
Done.
|
| + _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.
|
| + 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.
|
| + // Let it fall-through, as we already are at the top of the stack. |
| + queue.removeFirst()(); |
| + } |
| + }); |
| + } |
| } |
| /** |