Apply new format to snippets and template
This commit is contained in:
@ -5,9 +5,9 @@ tags: browser,function,advanced,promise,url
|
||||
|
||||
Runs a function in a separate thread by using a [Web Worker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers), 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.
|
||||
- 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.
|
||||
|
||||
```js
|
||||
const runAsync = fn => {
|
||||
@ -44,4 +44,4 @@ runAsync(longRunningFunction).then(console.log); // 209685000000
|
||||
runAsync(() => 10 ** 3).then(console.log); // 1000
|
||||
let outsideVariable = 50;
|
||||
runAsync(() => typeof outsideVariable).then(console.log); // 'undefined'
|
||||
```
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user