Add new sleep()
function and deprecate resolve()
and reject()
functions
#51
+198
−14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This changeset adds a new
sleep()
function and deprecates theresolve()
andreject()
functions in favor of the newsleep()
function.The new
sleep()
function does precisely what the currentresolve()
function does: It creates a promise that will be fulfilled in a given number of seconds. The only difference is that thesleep()
function resolves with no value, whereas theresolve()
function resolves with the number of seconds. The previous type was a pretty arbitrary design decision I made, the new type now matches howusleep()
returns avoid
.Using the name
sleep()
makes a lot more sense as introducing an asynchronous delay is a rather common requirement and it makes sense to mimic PHP's built-insleep()
function. On top of this, this also helps avoid any ambiguities, as theReact\Promise\resolve()
function does something entirely different than theReact\Promise\Timer\resolve()
function (same local name, only different namespace). This is also a major DX improvement, as IDE autocompletion would always suggest the wrong function import, let alone the fact that you wouldn't look for a function named "resolve" if you want to "sleep".Similarly, the
reject()
function was mostly added to complement theresolve()
function, but I don't see any real-world use cases for this. Implementing this on top of thesleep()
function is trivial (see its implementation), so I will argue it provides very little value.Builds on top of #49