Skip to content

Commit

Permalink
add FiberHandle module, for holding a reference to a running fiber (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart authored and mikearnaldi committed Apr 16, 2024
1 parent 2eff431 commit 1b5f0c7
Show file tree
Hide file tree
Showing 11 changed files with 810 additions and 117 deletions.
7 changes: 7 additions & 0 deletions .changeset/brave-eggs-allow.md
@@ -0,0 +1,7 @@
---
"effect": minor
---

close FiberHandle/FiberSet/FiberMap when it is released

When they are closed, fibers can no longer be added to them.
5 changes: 5 additions & 0 deletions .changeset/odd-ears-build.md
@@ -0,0 +1,5 @@
---
"effect": patch
---

add FiberMap.has/unsafeHas api
24 changes: 24 additions & 0 deletions .changeset/sweet-apples-applaud.md
@@ -0,0 +1,24 @@
---
"effect": patch
---

add FiberHandle module, for holding a reference to a running fiber

```ts
import { Effect, FiberHandle } from "effect"

Effect.gen(function* (_) {
const handle = yield* _(FiberHandle.make())

// run some effects
yield* _(FiberHandle.run(handle, Effect.never))
// this will interrupt the previous fiber
yield* _(FiberHandle.run(handle, Effect.never))
// this will not run, as a fiber is already running
yield* _(FiberHandle.run(handle, Effect.never, { onlyIfMissing: true }))

yield* _(Effect.sleep(1000))
}).pipe(
Effect.scoped // The fiber will be interrupted when the scope is closed
)
```

0 comments on commit 1b5f0c7

Please sign in to comment.