From e3bb50e2c9d6c0e547f20c946320f82d1c69530b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Sun, 16 Nov 2025 05:05:06 +0100 Subject: [PATCH] Query work --- packages/effect-fc/src/Query.ts | 39 ++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/packages/effect-fc/src/Query.ts b/packages/effect-fc/src/Query.ts index 8c549b8..abe6e1c 100644 --- a/packages/effect-fc/src/Query.ts +++ b/packages/effect-fc/src/Query.ts @@ -1,4 +1,5 @@ -import { type Effect, Pipeable, Predicate, type Stream } from "effect" +import { Effect, Fiber, Option, Pipeable, Predicate, Stream, type Subscribable, type SubscriptionRef } from "effect" +import type * as Result from "./Result.js" export const QueryTypeId: unique symbol = Symbol.for("@effect-fc/Query/Query") @@ -9,8 +10,11 @@ extends Pipeable.Pipeable { readonly [QueryTypeId]: QueryTypeId readonly key: Stream.Stream - readonly query: (key: K) => Effect.Effect + readonly f: (key: K) => Effect.Effect readonly initialProgress: P + + readonly fiber: Subscribable.Subscribable>>> + readonly result: Subscribable.Subscribable> } class QueryImpl @@ -19,11 +23,40 @@ extends Pipeable.Class() implements Query { constructor( readonly key: Stream.Stream, - readonly query: (key: K) => Effect.Effect, + readonly f: (key: K) => Effect.Effect, readonly initialProgress: P, + + readonly fiber: SubscriptionRef.SubscriptionRef>>>, + readonly result: SubscriptionRef.SubscriptionRef>, ) { super() } + + query(key: K) { + return this.result.pipe( + Effect.andThen(Option.match({ + + })) + ) + } } export const isQuery = (u: unknown): u is Query => Predicate.hasProperty(u, QueryTypeId) + +export const run = ( + self: Query +) => Stream.runForEach(self.key, +) + +export const query = ( + self: Query, + key: K, +) => self.fiberRef.pipe( + Effect.andThen(Option.match({ + onSome: Fiber.interrupt, + onNone: () => Effect.void, + })), + Effect.andThen(Effect.forkScoped( + + )) +)