Skip to content

Commit

Permalink
ensure Effect.timeoutTo sleep is interrupted (#4189)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart authored Dec 25, 2024
1 parent df82e92 commit bfe8027
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 47 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-mice-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

ensure Effect.timeoutTo sleep is interrupted
99 changes: 52 additions & 47 deletions packages/effect/src/internal/effect/circular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,58 +583,63 @@ export const timeoutTo = dual<
readonly duration: Duration.DurationInput
}
) => Effect.Effect<B | B1, E, R>
>(2, (self, { duration, onSuccess, onTimeout }) =>
core.fiberIdWith((parentFiberId) =>
fiberRuntime.raceFibersWith(
self,
core.interruptible(effect.sleep(duration)),
{
onSelfWin: (winner, loser) =>
core.flatMap(
winner.await,
(exit) => {
if (exit._tag === "Success") {
return core.flatMap(
winner.inheritAll,
() =>
core.as(
>(
2,
(self, { duration, onSuccess, onTimeout }) =>
core.fiberIdWith((parentFiberId) =>
core.uninterruptibleMask((restore) =>
fiberRuntime.raceFibersWith(
restore(self),
core.interruptible(effect.sleep(duration)),
{
onSelfWin: (winner, loser) =>
core.flatMap(
winner.await,
(exit) => {
if (exit._tag === "Success") {
return core.flatMap(
winner.inheritAll,
() =>
core.as(
core.interruptAsFiber(loser, parentFiberId),
onSuccess(exit.value)
)
)
} else {
return core.flatMap(
core.interruptAsFiber(loser, parentFiberId),
onSuccess(exit.value)
() => core.exitFailCause(exit.cause)
)
)
} else {
return core.flatMap(
core.interruptAsFiber(loser, parentFiberId),
() => core.exitFailCause(exit.cause)
)
}
}
),
onOtherWin: (winner, loser) =>
core.flatMap(
winner.await,
(exit) => {
if (exit._tag === "Success") {
return core.flatMap(
winner.inheritAll,
() =>
core.as(
}
}
),
onOtherWin: (winner, loser) =>
core.flatMap(
winner.await,
(exit) => {
if (exit._tag === "Success") {
return core.flatMap(
winner.inheritAll,
() =>
core.as(
core.interruptAsFiber(loser, parentFiberId),
onTimeout()
)
)
} else {
return core.flatMap(
core.interruptAsFiber(loser, parentFiberId),
onTimeout()
() => core.exitFailCause(exit.cause)
)
)
} else {
return core.flatMap(
core.interruptAsFiber(loser, parentFiberId),
() => core.exitFailCause(exit.cause)
)
}
}
),
otherScope: globalScope
}
}
}
),
otherScope: globalScope
}
)
)
)
))
)

// circular with Synchronized

Expand Down

0 comments on commit bfe8027

Please sign in to comment.