diff --git a/README.md b/README.md index 39fc8c4fa..d6f750d77 100644 --- a/README.md +++ b/README.md @@ -3275,9 +3275,8 @@ Return a promise, listening for `onmessage` and `onerror` events and resolving t ```js const runAsync = fn => { - const blob = `var fn = ${fn.toString()}; postMessage(fn());`; const worker = new Worker( - URL.createObjectURL(new Blob([blob]), { + URL.createObjectURL(new Blob([`postMessage((${fn})());`]), { type: 'application/javascript; charset=utf-8' }) ); diff --git a/docs/index.html b/docs/index.html index fc78ace94..110dec1cb 100644 --- a/docs/index.html +++ b/docs/index.html @@ -700,9 +700,8 @@ document.body? (window.location.href = url) : window.location.replace(url);
redirect('https://google.com');
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.
const runAsync = fn => { - const blob = `var fn = ${fn.toString()}; postMessage(fn());`; const worker = new Worker( - URL.createObjectURL(new Blob([blob]), { + URL.createObjectURL(new Blob([`postMessage((${fn})());`]), { type: 'application/javascript; charset=utf-8' }) );