Converts an asynchronous function to return a promise.

In Node 8+, you can use util.promisify

Use currying to return a function returning a Promise that calls the original function.
Use the operator to pass in all the parameters.

继续阅读 30秒学会 JavaScript 片段 – promisify

Performs left-to-right function composition for asynchronous functions.

Use Array.prototype.reduce() and the spread operator (...) to perform function composition using Promise.then().
The functions can return a combination of normal values, Promises or be async, returning through await.
All functions must accept a single argument.

继续阅读 30秒学会 JavaScript 片段 – pipeAsyncFunctions

Runs a function in a separate thread by using a Web Worker, allowing long running functions to not block the UI.

Create a new Worker using a Blob object URL, the contents of which should be the stringified version of the supplied function.
Immediately post the return value of calling the function back.
Return a promise, listening for onmessage and onerror events and resolving the data posted back from the worker, or throwing an error.

继续阅读 30秒学会 JavaScript 片段 – runAsync