Skip to content

Commit 0b952ae

Browse files
author
Weedshaker
committed
webWorker support async
1 parent 91f7316 commit 0b952ae

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/WebWorker.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ export const WebWorker = (ChosenHTMLElement = HTMLElement) => class WebWorker ex
4141
func = func.replace(/this\./g, '')
4242
func = func.replace(new RegExp(`${this.constructor.name}\\.`, 'g'), '')
4343
func = /^.*?=>.*?/.test(func) ? `(${func})` : !/^function/.test(func) ? `function ${func}` : func
44-
const response = `onmessage=(event)=>{postMessage(${func}(...event.data))}`
44+
func = func.replace(/(.*)async\s(.*)/s, 'await async $1$2') // fix async function
45+
func = func.replace(/function\s#/, 'function ') // fix private functions
46+
const response = `onmessage=async (event)=>{postMessage(${func}(...event.data))}`
4547
let blob
4648
try {
4749
blob = new Blob([response], { type: 'application/javascript' })

0 commit comments

Comments
 (0)