Skip to content

Commit

Permalink
Merge pull request #2173 from armanbilge/polyfill-webworker
Browse files Browse the repository at this point in the history
Implement executor polyfill for web workers
  • Loading branch information
djspiewak authored Jul 30, 2021
2 parents c6b120f + 01c86ed commit 306e976
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,21 @@ private[unsafe] object PolyfillExecutionContext extends ExecutionContext {
js.Dynamic.global.postMessage(messagePrefix + handle, "*")
()
}
} else if (js.typeOf(js.Dynamic.global.MessageChannel) != Undefined) {
val channel = js.Dynamic.newInstance(js.Dynamic.global.MessageChannel)()

channel.port1.onmessage = { event: js.Dynamic =>
runIfPresent(event.data.asInstanceOf[Int])
}

{ k =>
val handle = nextHandle
nextHandle += 1

tasksByHandle += (handle -> k)
channel.port2.postMessage(handle)
()
}
} else {
// we don't try to look for process.nextTick since scalajs doesn't support old node
// we're also not going to bother fast-pathing for IE6; just fall through
Expand Down

0 comments on commit 306e976

Please sign in to comment.