MCPcopy Create free account
hub / github.com/datner/react-effect / run

Method run

src/internal/fiberStore.ts:65–93  ·  view source on GitHub ↗
(stream: Stream.Stream<R, E, A>)

Source from the content-addressed store, hash-verified

63 }
64 | undefined = undefined
65 public run(stream: Stream.Stream<R, E, A>) {
66 this.interruptIfRunning()
67 this.stream = stream
68
69 const interruptedRef = Ref.unsafeMake(false)
70 const maybeSetResult = (result: Result.Result<E, A>) =>
71 Effect.flatMap(
72 Ref.get(interruptedRef),
73 (interrupted) =>
74 interrupted
75 ? Effect.unit
76 : Effect.sync(() => this.setResult(result))
77 )
78
79 const fiber = pipe(
80 Stream.suspend(() => {
81 this.setResult(Result.waiting(this.resultBag.result))
82 return stream
83 }),
84 Stream.runForEach((_) => maybeSetResult(Result.success(_))),
85 Effect.catchAllCause((cause) => maybeSetResult(Result.failCause(cause))),
86 Runtime.runFork(this.runtime)
87 )
88
89 this.fiberState = {
90 fiber,
91 interruptedRef
92 }
93 }
94 public interruptIfRunning() {
95 if (this.fiberState) {
96 Effect.runFork(

Callers 3

maybeResumeMethod · 0.95
makeFunction · 0.80
makeFunction · 0.80

Calls 2

interruptIfRunningMethod · 0.95
setResultMethod · 0.95

Tested by

no test coverage detected