Skip to content

Commit

Permalink
fix queue-microtask
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink committed Nov 9, 2023
1 parent 2950e79 commit 18300c0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/util-actor/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import {mailbox as createMailbox, type IMailbox} from "./mailbox"

// eslint-disable-next-line @typescript-eslint/no-var-requires
const queueMicrotask = require("queue-microtask")
let promise: any
const _queueMicrotask = (cb: any) =>
(promise || (promise = Promise.resolve())).then(cb).catch((err: any) =>
setTimeout(() => {
throw err
}, 0)
)

export const INIT = "INIT"
export const SUBSCRIBE = "SUBSCRIBE"
Expand Down Expand Up @@ -189,7 +194,7 @@ export const spawn = <Handlers extends ActorHandlers>(
fn = fromHandlers<Handlers>(fnOrHandlers)
else fn = fnOrHandlers

queueMicrotask(async () => {
_queueMicrotask(async () => {
await fn(ctx)
kill(addr)
})
Expand Down

0 comments on commit 18300c0

Please sign in to comment.