diff --git a/packages/effect-fc/src/Query.ts b/packages/effect-fc/src/Query.ts index 33578d4..159198e 100644 --- a/packages/effect-fc/src/Query.ts +++ b/packages/effect-fc/src/Query.ts @@ -17,9 +17,9 @@ extends Pipeable.Pipeable { readonly fiber: Subscribable.Subscribable>> readonly result: Subscribable.Subscribable> - fetch(key: K): Effect.Effect>> - readonly refetch: Effect.Effect>, Cause.NoSuchElementException> - readonly refresh: Effect.Effect>, Cause.NoSuchElementException> + fetch(key: K): Effect.Effect> + readonly refetch: Effect.Effect, Cause.NoSuchElementException> + readonly refresh: Effect.Effect, Cause.NoSuchElementException> } class QueryImpl @@ -41,12 +41,35 @@ extends Pipeable.Class() implements Query { } get interrupt(): Effect.Effect { - return this.fiber.pipe( - Effect.andThen(Option.match({ - onSome: Fiber.interrupt, - onNone: () => Effect.void, - })), - Effect.andThen(Effect.sleep("0 millis")), + return Effect.andThen(this.fiber, Option.match({ + onSome: Fiber.interrupt, + onNone: () => Effect.void, + })) + } + + fetch(key: K): Effect.Effect> { + return this.interrupt.pipe( + Effect.andThen(SubscriptionRef.set(this.latestKey, Option.some(key))), + Effect.andThen(Effect.provide(this.start(key), this.context)), + Effect.andThen(sub => this.watch(sub)), + ) + } + + get refetch(): Effect.Effect, Cause.NoSuchElementException> { + return this.interrupt.pipe( + Effect.andThen(this.latestKey), + Effect.andThen(identity), + Effect.andThen(key => Effect.provide(this.start(key), this.context)), + Effect.andThen(sub => this.watch(sub)), + ) + } + + get refresh(): Effect.Effect, Cause.NoSuchElementException> { + return this.interrupt.pipe( + Effect.andThen(this.latestKey), + Effect.andThen(identity), + Effect.andThen(key => Effect.provide(this.start(key, true), this.context)), + Effect.andThen(sub => this.watch(sub)), ) } @@ -88,32 +111,6 @@ extends Pipeable.Class() implements Query { ), ) } - - fetch(key: K): Effect.Effect>> { - return this.interrupt.pipe( - Effect.andThen(SubscriptionRef.set(this.latestKey, Option.some(key))), - Effect.andThen(this.start(key)), - Effect.provide(this.context), - ) - } - - get refetch(): Effect.Effect>, Cause.NoSuchElementException> { - return this.interrupt.pipe( - Effect.andThen(this.latestKey), - Effect.andThen(identity), - Effect.andThen(key => this.start(key)), - Effect.provide(this.context), - ) - } - - get refresh(): Effect.Effect>, Cause.NoSuchElementException> { - return this.interrupt.pipe( - Effect.andThen(this.latestKey), - Effect.andThen(identity), - Effect.andThen(key => this.start(key, true)), - Effect.provide(this.context), - ) - } } export const isQuery = (u: unknown): u is Query => Predicate.hasProperty(u, QueryTypeId)