Skip to content

Commit eeed4e0

Browse files
thorn0jleyba
authored andcommitted
[js] consequences of replacing Promise->ManagedPromise (#3129)
Also add a link to an article explaining microtasks.
1 parent c0a3b39 commit eeed4e0

1 file changed

Lines changed: 19 additions & 18 deletions

File tree

javascript/node/selenium-webdriver/lib/promise.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@
103103
*
104104
* Whenever the control flow creates a new task queue, it will automatically
105105
* begin executing tasks in the next available turn of the event loop. This
106-
* execution is scheduled using a "micro-task" timer, such as a (native)
107-
* `ManagedPromise.then()` callback.
106+
* execution is [scheduled as a microtask][MicrotasksArticle] like e.g. a
107+
* (native) `Promise.then()` callback.
108108
*
109109
* setTimeout(() => console.log('a'));
110-
* ManagedPromise.resolve().then(() => console.log('b')); // A native promise.
110+
* Promise.resolve().then(() => console.log('b')); // A native promise.
111111
* flow.execute(() => console.log('c'));
112-
* ManagedPromise.resolve().then(() => console.log('d'));
112+
* Promise.resolve().then(() => console.log('d'));
113113
* setTimeout(() => console.log('fin'));
114114
* // b
115115
* // c
@@ -118,13 +118,13 @@
118118
* // fin
119119
*
120120
* In the example above, b/c/d is logged before a/fin because native promises
121-
* and this module use "micro-task" timers, which have a higher priority than
122-
* "macro-tasks" like `setTimeout`.
121+
* and this module use "microtask" timers, which have a higher priority than
122+
* "macrotasks" like `setTimeout`.
123123
*
124124
* ## Task Execution
125125
*
126126
* Upon creating a task queue, and whenever an exisiting queue completes a task,
127-
* the control flow will schedule a micro-task timer to process any scheduled
127+
* the control flow will schedule a microtask timer to process any scheduled
128128
* tasks. This ensures no task is ever started within the same turn of the
129129
* JavaScript event loop in which it was scheduled, nor is a task ever started
130130
* within the same turn that another finishes.
@@ -161,7 +161,7 @@
161161
* ## ManagedPromise Integration
162162
*
163163
* In addition to the {@link ControlFlow} class, the promise module also exports
164-
* a [ManagedPromise/A+] {@linkplain ManagedPromise implementation} that is deeply
164+
* a [Promise/A+] {@linkplain ManagedPromise implementation} that is deeply
165165
* integrated with the ControlFlow. First and foremost, each promise
166166
* {@linkplain ManagedPromise#then() callback} is scheduled with the
167167
* control flow as a task. As a result, each callback is invoked in its own turn
@@ -467,17 +467,17 @@
467467
*
468468
* ES6 promises do not require users to handle a promise rejections. This can
469469
* result in subtle bugs as the rejections are silently "swallowed" by the
470-
* ManagedPromise class.
470+
* Promise class.
471471
*
472-
* ManagedPromise.reject(Error('boom'));
472+
* Promise.reject(Error('boom'));
473473
* // ... *crickets* ...
474474
*
475475
* Selenium's promise module, on the other hand, requires that every rejection
476476
* be explicitly handled. When a {@linkplain ManagedPromise ManagedPromise} is
477477
* rejected and no callbacks are defined on that promise, it is considered an
478-
* _unhandled rejection_ and reproted to the active task queue. If the rejection
478+
* _unhandled rejection_ and reported to the active task queue. If the rejection
479479
* remains unhandled after a single turn of the [event loop][JSEL] (scheduled
480-
* with a micro-task), it will propagate up the stack.
480+
* with a microtask), it will propagate up the stack.
481481
*
482482
* ## Error Propagation
483483
*
@@ -582,9 +582,9 @@
582582
*
583583
* Bottom line: you __*must*__ handle rejected promises.
584584
*
585-
* # ManagedPromise/A+ Compatibility
585+
* # Promise/A+ Compatibility
586586
*
587-
* This `promise` module is compliant with the [ManagedPromise/A+][] specification
587+
* This `promise` module is compliant with the [Promise/A+] specification
588588
* except for sections `2.2.6.1` and `2.2.6.2`:
589589
*
590590
* >
@@ -598,7 +598,7 @@
598598
* Specifically, the conformance tests contains the following scenario (for
599599
* brevity, only the fulfillment version is shown):
600600
*
601-
* var p1 = ManagedPromise.resolve();
601+
* var p1 = Promise.resolve();
602602
* p1.then(function() {
603603
* console.log('A');
604604
* p1.then(() => console.log('B'));
@@ -623,7 +623,8 @@
623623
*
624624
* [JSEL]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop
625625
* [GF]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*
626-
* [ManagedPromise/A+]: https://promisesaplus.com/
626+
* [Promise/A+]: https://promisesaplus.com/
627+
* [MicrotasksArticle]: https://jakearchibald.com/2015/tasks-microtasks-queues-and-schedules/
627628
*/
628629

629630
'use strict';
@@ -667,7 +668,7 @@ function getUid(obj) {
667668

668669

669670
/**
670-
* Runs the given function after a micro-task yield.
671+
* Runs the given function after a microtask yield.
671672
* @param {function()} fn The function to run.
672673
*/
673674
function asyncRun(fn) {
@@ -2622,7 +2623,7 @@ class MicroTask {
26222623
}
26232624

26242625
/**
2625-
* Runs the given function after a micro-task yield.
2626+
* Runs the given function after a microtask yield.
26262627
* @param {function()} fn The function to run.
26272628
*/
26282629
static run(fn) {

0 commit comments

Comments
 (0)