mirror of
https://github.com/Effect-TS/effect.git
synced 2026-12-03 03:25:40 +08:00
port Activity waitForZero (#797)
This commit is contained in:
@@ -599,12 +599,9 @@ export const wrapActivityResult = <A, E, R>(
|
||||
const instance = ServiceMap.get(services, InstanceTag)
|
||||
const state = instance.activityState
|
||||
if (instance.suspended) {
|
||||
return state.count > 0
|
||||
? state.latch.await.pipe(
|
||||
Effect.andThen(Effect.yieldNow),
|
||||
Effect.andThen(suspend(instance))
|
||||
)
|
||||
: suspend(instance)
|
||||
return waitForZero(instance).pipe(
|
||||
Effect.andThen(suspend(instance))
|
||||
)
|
||||
}
|
||||
if (state.count === 0) state.latch.closeUnsafe()
|
||||
state.count++
|
||||
@@ -624,11 +621,24 @@ export const wrapActivityResult = <A, E, R>(
|
||||
return state.count === 0
|
||||
? state.latch.open
|
||||
: isSuspended
|
||||
? state.latch.await
|
||||
? waitForZero(instance)
|
||||
: Effect.void
|
||||
})
|
||||
})
|
||||
|
||||
const waitForZero = Effect.fnUntraced(function*(instance: WorkflowInstance["Service"]) {
|
||||
const state = instance.activityState
|
||||
while (true) {
|
||||
if (state.count > 0) {
|
||||
yield* state.latch.await
|
||||
yield* Effect.yieldNow
|
||||
continue
|
||||
}
|
||||
yield* Effect.yieldNow
|
||||
if (state.count === 0) return
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* Accesses the workflow scope.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user