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

Unified Diff: sdk/lib/async/event_loop.dart

Issue 26993002: Add factory-method for scheduleMicrotask, as well as a (failing) test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/async/async_sources.gypi ('k') | sdk/lib/async/schedule_microtask.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/async/event_loop.dart
diff --git a/sdk/lib/async/event_loop.dart b/sdk/lib/async/event_loop.dart
deleted file mode 100644
index 42c25ecdbce26ea8f2741eb05c1e497bed612445..0000000000000000000000000000000000000000
--- a/sdk/lib/async/event_loop.dart
+++ /dev/null
@@ -1,79 +0,0 @@
-// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-part of dart.async;
-
-typedef void _AsyncCallback();
-
-bool _callbacksAreEnqueued = false;
-Queue<_AsyncCallback> _asyncCallbacks = new Queue<_AsyncCallback>();
-
-void _asyncRunCallback() {
- // As long as we are iterating over the registered callbacks we don't
- // unset the [_callbacksAreEnqueued] boolean.
- while (!_asyncCallbacks.isEmpty) {
- Function callback = _asyncCallbacks.removeFirst();
- try {
- callback();
- } catch (e) {
- _AsyncRun._enqueueImmediate(_asyncRunCallback);
- rethrow;
- }
- }
- // Any new callback must register a callback function now.
- _callbacksAreEnqueued = false;
-}
-
-void _scheduleAsyncCallback(callback) {
- // Optimizing a group of Timer.run callbacks to be executed in the
- // same Timer callback.
- _asyncCallbacks.add(callback);
- if (!_callbacksAreEnqueued) {
- _AsyncRun._enqueueImmediate(_asyncRunCallback);
- _callbacksAreEnqueued = true;
- }
-}
-
-/**
- * Runs the given [callback] asynchronously.
- *
- * Callbacks registered through this function are always executed in order and
- * are guaranteed to run before other asynchronous events (like [Timer] events,
- * or DOM events).
- *
- * Warning: it is possible to starve the DOM by registering asynchronous
- * callbacks through this method. For example the following program runs
- * the callbacks without ever giving the Timer callback a chance to execute:
- *
- * Timer.run(() { print("executed"); }); // Will never be executed;
- * foo() {
- * scheduleMicrotask(foo); // Schedules [foo] in front of other events.
- * }
- * main() {
- * foo();
- * }
- */
-void scheduleMicrotask(void callback()) {
- if (Zone.current == Zone.ROOT) {
- // No need to bind the callback. We know that the root's scheduleMicrotask
- // will be invoked in the root zone.
- Zone.current.scheduleMicrotask(callback);
- return;
- }
- Zone.current.scheduleMicrotask(
- Zone.current.bindCallback(callback, runGuarded: true));
-}
-
-/**
- * *DEPRECATED*. Use [scheduleMicrotask] instead.
- */
-@deprecated
-void runAsync(void callback()) {
- scheduleMicrotask(callback);
-}
-
-class _AsyncRun {
- /** Enqueues the given callback before any other event in the event-loop. */
- external static void _enqueueImmediate(void callback());
-}
« no previous file with comments | « sdk/lib/async/async_sources.gypi ('k') | sdk/lib/async/schedule_microtask.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698