@antoniovdlc/defer
Advanced tools
Comparing version 0.1.1 to 0.1.2
{ | ||
"name": "@antoniovdlc/defer", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Go-like defer functions in JavaScript.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.cjs.js", |
@@ -54,3 +54,3 @@ # defer | ||
For sync functions, `defer` simply puts the `fn` at the bottom of the call stack using `setTimeout(fn, 0)`. | ||
For sync functions, `defer` simply puts the `fn` on the call stack using `setTimeout(fn, 0)`. | ||
For async functions, it is a bit more tricky, and we keep track of deferred functions within the `caller` itself, via the property `__$_deferArr`. | ||
@@ -64,2 +64,7 @@ > Using `defer` in async functions requires them to be wrapper with `deferrable` to work properly. | ||
`defer`red functions are run sequentially, and as such, if one function throws an error, the following `defer`red functions won't run. | ||
`defer`red functions in a `deferrable` will not run if the wrapped function throws an error. | ||
## Examples | ||
@@ -70,3 +75,3 @@ | ||
function main() { | ||
defer(() => console.log("world"); | ||
defer(() => console.log("world"), main); | ||
console.log("hello"); | ||
@@ -81,6 +86,6 @@ } | ||
function f() { | ||
defer(() => console.log("1), f); | ||
defer(() => console.log("1"), f); | ||
console.log("2"); | ||
defer(() => console.log("3"), f); | ||
console.log("4") | ||
console.log("4"); | ||
} | ||
@@ -101,3 +106,3 @@ | ||
defer(() => console.log("3"), fn); | ||
console.log("4") | ||
console.log("4"); | ||
}); | ||
@@ -104,0 +109,0 @@ |
11890
143