MCPcopy Create free account
hub / github.com/effect-app/libs / query

Function query

repos/effect/packages/effect/src/unstable/reactivity/Reactivity.ts:135–175  ·  view source on GitHub ↗
(
    keys: ReadonlyArray<unknown> | ReadonlyRecord<string, ReadonlyArray<unknown>>,
    effect: Effect.Effect<A, E, R>
  )

Source from the content-addressed store, hash-verified

133 }
134
135 const query = <A, E, R>(
136 keys: ReadonlyArray<unknown> | ReadonlyRecord<string, ReadonlyArray<unknown>>,
137 effect: Effect.Effect<A, E, R>
138 ): Effect.Effect<Queue.Dequeue<A, E>, never, R | Scope.Scope> =>
139 Effect.gen(function*() {
140 const services = yield* Effect.context<Scope.Scope | R>()
141 const scope = Context.get(services, Scope.Scope)
142 const results = yield* Queue.make<A, E>()
143 const runFork = flow(Effect.runForkWith(services), Fiber.runIn(scope))
144
145 let running = false
146 let pending = false
147 const handleExit = (exit: Exit.Exit<A, E>) => {
148 if (exit._tag === "Failure") {
149 Queue.failCauseUnsafe(results, exit.cause)
150 } else {
151 Queue.offerUnsafe(results, exit.value)
152 }
153 if (pending) {
154 pending = false
155 runFork(effect).addObserver(handleExit)
156 } else {
157 running = false
158 }
159 }
160
161 function run() {
162 if (running) {
163 pending = true
164 return
165 }
166 running = true
167 runFork(effect).addObserver(handleExit)
168 }
169
170 const cancel = registerUnsafe(keys, run)
171 yield* Scope.addFinalizer(scope, Effect.sync(cancel))
172 run()
173
174 return results as Queue.Dequeue<A, E>
175 })
176
177 const stream = <A, E, R>(
178 tables: ReadonlyArray<unknown> | ReadonlyRecord<string, ReadonlyArray<unknown>>,

Callers 2

streamFunction · 0.70
SqlSchema.test.tsFile · 0.50

Calls 7

registerUnsafeFunction · 0.85
addFinalizerMethod · 0.80
syncMethod · 0.80
runFunction · 0.70
contextMethod · 0.65
getMethod · 0.65
makeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…