(stream: Stream.Stream<R, E, A>)
| 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( |
no test coverage detected