Skip to content

Commit

Permalink
attach Stream.toReadableStream fibers to scope (#2834)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed May 23, 2024
1 parent 5133ca9 commit 031c712
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/metal-parrots-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

attach Stream.toReadableStream fibers to scope
10 changes: 7 additions & 3 deletions packages/effect/src/internal/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6555,7 +6555,7 @@ export const toReadableStreamRuntime = dual<
<A, E, XR, R extends XR>(self: Stream.Stream<A, E, R>, runtime: Runtime.Runtime<XR>) => ReadableStream<A>
>(2, <A, E, XR, R extends XR>(self: Stream.Stream<A, E, R>, runtime: Runtime.Runtime<XR>): ReadableStream<A> => {
const runSync = Runtime.runSync(runtime)
const runPromise = Runtime.runPromise(runtime)
const runFork = Runtime.runFork(runtime)

let pull: Effect.Effect<void, never, R>
let scope: Scope.CloseableScope
Expand Down Expand Up @@ -6588,10 +6588,14 @@ export const toReadableStreamRuntime = dual<
)
},
pull() {
return runPromise(pull)
return new Promise<void>((resolve) => {
runFork(pull, { scope }).addObserver((_) => resolve())
})
},
cancel() {
return runPromise(Scope.close(scope, Exit.void))
return new Promise<void>((resolve) => {
runFork(Scope.close(scope, Exit.void)).addObserver((_) => resolve())
})
}
})
})
Expand Down

0 comments on commit 031c712

Please sign in to comment.