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