User talk:Poltawski/Javascript promises: Difference between revisions
From MoodleDocs
(Created page with " == Promises == Promises are used extensively in modern Moodle Javascript APIs to handle asynchronous situations. It is unfortunately common to misunderstand how they operat...") |
(No difference)
|
Revision as of 09:59, 1 June 2017
Promises
Promises are used extensively in modern Moodle Javascript APIs to handle asynchronous situations. It is unfortunately common to misunderstand how they operate and introduce bugs which only expose themselves in asynchronous edge cases (see article we have a problem with promises). In order to make use of promises in Moodle more understandable, consistent and avoid edge case bugs, we have adopted best practices suggested by Nolan Lawson and verified by eslint-plugin-promise.
What can we do here? There are three things:
- return another promise
- return a synchronous value (or undefined)
- throw a synchronous error