Skip to content

Commit

Permalink
skip running effects in FiberHandle/Map if not required
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Apr 16, 2024
1 parent 1713d63 commit 3143c02
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-bees-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

skip running effects in FiberHandle/Map if not required
4 changes: 4 additions & 0 deletions packages/effect/src/FiberHandle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ export const run: {
return Effect.suspend(() => {
if (self.state._tag === "Closed") {
return Effect.interrupt
} else if (self.state.fiber !== undefined && options?.onlyIfMissing === true) {
return set(self, Effect.runFork(Effect.never), options)
}
return Effect.uninterruptibleMask((restore) =>
Effect.tap(
Expand All @@ -321,6 +323,8 @@ export const run: {
Effect.suspend(() => {
if (self.state._tag === "Closed") {
return Effect.interrupt
} else if (self.state.fiber !== undefined && options?.onlyIfMissing === true) {
return set(self, Effect.runFork(Effect.never), options)
}
return Effect.uninterruptibleMask((restore) =>
Effect.tap(
Expand Down
4 changes: 4 additions & 0 deletions packages/effect/src/FiberMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ export const run: {
return Effect.suspend(() => {
if (self.state._tag === "Closed") {
return Effect.interrupt
} else if (unsafeHas(self, key) && options?.onlyIfMissing === true) {
return set(self, key, Effect.runFork(Effect.never), options)
}
return Effect.uninterruptibleMask((restore) =>
Effect.tap(
Expand All @@ -426,6 +428,8 @@ export const run: {
Effect.suspend(() => {
if (self.state._tag === "Closed") {
return Effect.interrupt
} else if (unsafeHas(self, key) && options?.onlyIfMissing === true) {
return set(self, key, Effect.runFork(Effect.never), options)
}
return Effect.uninterruptibleMask((restore) =>
Effect.tap(
Expand Down

0 comments on commit 3143c02

Please sign in to comment.