Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 --- | 1 --- |
| 2 layout: default | 2 layout: default |
| 3 title: "The Event Loop and Dart" | 3 title: "The Event Loop and Dart" |
| 4 description: "Learn how Dart handles the event queue and microtask queue, so you can write better asynchronous code with fewer surprises." | 4 description: "Learn how Dart handles the event queue and microtask queue, so you can write better asynchronous code with fewer surprises." |
| 5 rel: | 5 rel: |
| 6 author: kathy-walrath | 6 author: kathy-walrath |
| 7 has-permalinks: true | 7 has-permalinks: true |
| 8 article: | 8 article: |
| 9 written_on: 2013-09-30 | 9 written_on: 2013-09-30 |
| 10 collection: performance | 10 collection: performance |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 ## How to schedule a task | 209 ## How to schedule a task |
| 210 | 210 |
| 211 When you need to specify some code to be executed later, | 211 When you need to specify some code to be executed later, |
| 212 you can use the following APIs provided by the dart:async library: | 212 you can use the following APIs provided by the dart:async library: |
| 213 | 213 |
| 214 1. The **Future** class, | 214 1. The **Future** class, |
| 215 which adds an item to the end of the **event queue**. | 215 which adds an item to the end of the **event queue**. |
| 216 1. The top-level **runAsync()** function, | 216 1. The top-level **runAsync()** function, |
| 217 which adds an item to the end of the **microtask queue**. | 217 which adds an item to the end of the **microtask queue**. |
| 218 | 218 |
| 219 <aside class="alert alert-warning" markdown="1"> | |
| 220 **Note:** | |
| 221 **runAsync()** is being renamed to **scheduleMicrotask().** | |
|
sethladd
2013/10/16 15:43:50
this might show up today. should we just change th
| |
| 222 (See the [announcement](https://groups.google.com/a/dartlang.org/forum/#!msg/mis c/7sAIhWXfIKQ/PzYJy1QqtWUJ).) | |
| 223 We'll update the text and figures soon. | |
| 224 </aside> | |
| 225 | |
| 219 Examples of using these APIs are in the next section under | 226 Examples of using these APIs are in the next section under |
| 220 [Event queue: new Future()](#event-queue-new-future) and | 227 [Event queue: new Future()](#event-queue-new-future) and |
| 221 [Microtask queue: runAsync()](#microtask-queue-runasync). | 228 [Microtask queue: runAsync()](#microtask-queue-runasync). |
| 222 | 229 |
| 223 ### Use the appropriate queue (usually: the event queue) | 230 ### Use the appropriate queue (usually: the event queue) |
| 224 | 231 |
| 225 Whenever possible, schedule tasks on the event queue, with Future. | 232 Whenever possible, schedule tasks on the event queue, with Future. |
| 226 Using the event queue helps keep the the microtask queue short, | 233 Using the event queue helps keep the the microtask queue short, |
| 227 reducing the likelihood of the microtask queue starving the event queue. | 234 reducing the likelihood of the microtask queue starving the event queue. |
| 228 | 235 |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 593 avoid compute-intensive tasks on either event loop. | 600 avoid compute-intensive tasks on either event loop. |
| 594 * To perform compute-intensive tasks, | 601 * To perform compute-intensive tasks, |
| 595 create additional isolates or workers. | 602 create additional isolates or workers. |
| 596 | 603 |
| 597 As you write asynchronous code, you might find these resources helpful: | 604 As you write asynchronous code, you might find these resources helpful: |
| 598 | 605 |
| 599 * [Using Future Based APIs](/articles/using-future-based-apis/) | 606 * [Using Future Based APIs](/articles/using-future-based-apis/) |
| 600 * [Futures and Error Handling](/articles/futures-and-error-handling/) | 607 * [Futures and Error Handling](/articles/futures-and-error-handling/) |
| 601 * [dart:async - Asynchronous Programming](/docs/dart-up-and-running/contents/ch0 3.html#ch03-asynchronous-programming) section of the library tour | 608 * [dart:async - Asynchronous Programming](/docs/dart-up-and-running/contents/ch0 3.html#ch03-asynchronous-programming) section of the library tour |
| 602 * [dart:async API reference](http://api.dartlang.org/dart_async.html) | 609 * [dart:async API reference](http://api.dartlang.org/dart_async.html) |
| OLD | NEW |