(
keys: ReadonlyArray<unknown> | ReadonlyRecord<string, ReadonlyArray<unknown>>,
effect: Effect.Effect<A, E, R>
)
| 89 | } |
| 90 | |
| 91 | const query = <A, E, R>( |
| 92 | keys: ReadonlyArray<unknown> | ReadonlyRecord<string, ReadonlyArray<unknown>>, |
| 93 | effect: Effect.Effect<A, E, R> |
| 94 | ): Effect.Effect<Mailbox.ReadonlyMailbox<A, E>, never, R | Scope.Scope> => |
| 95 | Effect.gen(function*() { |
| 96 | const scope = yield* Effect.scope |
| 97 | const results = yield* Mailbox.make<A, E>() |
| 98 | const runFork = yield* FiberHandle.makeRuntime<R>() |
| 99 | |
| 100 | let running = false |
| 101 | let pending = false |
| 102 | let stopped = false |
| 103 | const handleExit = (exit: Exit.Exit<A, E>) => { |
| 104 | if (exit._tag === "Failure") { |
| 105 | stopped = true |
| 106 | pending = false |
| 107 | running = false |
| 108 | cancel() |
| 109 | results.unsafeDone(Exit.failCause(exit.cause)) |
| 110 | return |
| 111 | } else { |
| 112 | results.unsafeOffer(exit.value) |
| 113 | } |
| 114 | if (pending) { |
| 115 | pending = false |
| 116 | runFork(effect).addObserver(handleExit) |
| 117 | } else { |
| 118 | running = false |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | function run() { |
| 123 | if (stopped) return |
| 124 | if (running) { |
| 125 | pending = true |
| 126 | return |
| 127 | } |
| 128 | running = true |
| 129 | runFork(effect).addObserver(handleExit) |
| 130 | } |
| 131 | |
| 132 | const cancel = unsafeRegister(keys, run) |
| 133 | yield* Scope.addFinalizer(scope, Effect.sync(cancel)) |
| 134 | run() |
| 135 | |
| 136 | return results as Mailbox.ReadonlyMailbox<A, E> |
| 137 | }) |
| 138 | |
| 139 | const stream = <A, E, R>( |
| 140 | tables: ReadonlyArray<unknown> | ReadonlyRecord<string, ReadonlyArray<unknown>>, |
no test coverage detected