0.2.1 #26
@@ -1,7 +1,7 @@
|
|||||||
import { Array, Cause, Chunk, type Duration, Effect, Equal, Exit, Fiber, flow, Hash, HashMap, identity, Option, ParseResult, Pipeable, Predicate, Ref, Schema, type Scope, Stream } from "effect"
|
import { Array, Cause, Chunk, type Context, type Duration, Effect, Equal, Exit, Fiber, flow, Hash, HashMap, identity, Option, ParseResult, Pipeable, Predicate, Ref, Schema, type Scope, Stream } from "effect"
|
||||||
import type { NoSuchElementException } from "effect/Cause"
|
|
||||||
import type * as React from "react"
|
import type * as React from "react"
|
||||||
import * as Component from "./Component.js"
|
import * as Component from "./Component.js"
|
||||||
|
import type * as Mutation from "./Mutation.js"
|
||||||
import * as PropertyPath from "./PropertyPath.js"
|
import * as PropertyPath from "./PropertyPath.js"
|
||||||
import * as Result from "./Result.js"
|
import * as Result from "./Result.js"
|
||||||
import * as Subscribable from "./Subscribable.js"
|
import * as Subscribable from "./Subscribable.js"
|
||||||
@@ -12,54 +12,88 @@ import * as SubscriptionSubRef from "./SubscriptionSubRef.js"
|
|||||||
export const FormTypeId: unique symbol = Symbol.for("@effect-fc/Form/Form")
|
export const FormTypeId: unique symbol = Symbol.for("@effect-fc/Form/Form")
|
||||||
export type FormTypeId = typeof FormTypeId
|
export type FormTypeId = typeof FormTypeId
|
||||||
|
|
||||||
export interface Form<in out A, in out I = A, out R = never, in out SA = void, in out SE = A, out SR = never, in out SP = never>
|
export interface Form<in out A, in out MA, in out I = A, in out R = never, in out ME = never, in out MR = never, in out MP = never>
|
||||||
extends Pipeable.Pipeable {
|
extends Pipeable.Pipeable {
|
||||||
readonly [FormTypeId]: FormTypeId
|
readonly [FormTypeId]: FormTypeId
|
||||||
|
|
||||||
readonly schema: Schema.Schema<A, I, R>
|
readonly schema: Schema.Schema<A, I, R>
|
||||||
readonly onSubmit: (value: NoInfer<A>) => Effect.Effect<SA, SE, SR>
|
readonly context: Context.Context<Scope.Scope | R>
|
||||||
readonly initialSubmitProgress: SP
|
readonly mutation: Mutation.Mutation<readonly [value: A], MA, ME, MR, MP>
|
||||||
readonly autosubmit: boolean
|
readonly autosubmit: boolean
|
||||||
readonly debounce: Option.Option<Duration.DurationInput>
|
readonly debounce: Option.Option<Duration.DurationInput>
|
||||||
|
|
||||||
readonly fieldCacheRef: Ref.Ref<HashMap.HashMap<FormFieldKey, FormField<unknown, unknown>>>
|
readonly value: Subscribable.Subscribable<Option.Option<A>>
|
||||||
readonly valueRef: SubscriptionRef.SubscriptionRef<Option.Option<A>>
|
readonly encodedValue: Subscribable.Subscribable<I>
|
||||||
readonly encodedValueRef: SubscriptionRef.SubscriptionRef<I>
|
readonly error: Subscribable.Subscribable<Option.Option<ParseResult.ParseError>>
|
||||||
readonly errorRef: SubscriptionRef.SubscriptionRef<Option.Option<ParseResult.ParseError>>
|
readonly validationFiber: Subscribable.Subscribable<Option.Option<Fiber.Fiber<A, ParseResult.ParseError>>>
|
||||||
readonly validationFiberRef: SubscriptionRef.SubscriptionRef<Option.Option<Fiber.Fiber<A, ParseResult.ParseError>>>
|
|
||||||
readonly submitResultRef: SubscriptionRef.SubscriptionRef<Result.Result<SA, SE, SP>>
|
|
||||||
|
|
||||||
readonly canSubmitSubscribable: Subscribable.Subscribable<boolean>
|
readonly canSubmit: Subscribable.Subscribable<boolean>
|
||||||
|
|
||||||
|
readonly submit: Effect.Effect<Option.Option<Result.Final<MA, ME, MP>>, Cause.NoSuchElementException>
|
||||||
}
|
}
|
||||||
|
|
||||||
class FormImpl<in out A, in out I = A, out R = never, in out SA = void, in out SE = A, out SR = never, in out SP = never>
|
export class FormImpl<in out A, in out MA, in out I = A, in out R = never, in out ME = never, in out MR = never, in out MP = never>
|
||||||
extends Pipeable.Class() implements Form<A, I, R, SA, SE, SR, SP> {
|
extends Pipeable.Class() implements Form<A, MA, I, R, ME, MR, MP> {
|
||||||
readonly [FormTypeId]: FormTypeId = FormTypeId
|
readonly [FormTypeId]: FormTypeId = FormTypeId
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
readonly schema: Schema.Schema<A, I, R>,
|
readonly schema: Schema.Schema<A, I, R>,
|
||||||
readonly onSubmit: (value: NoInfer<A>) => Effect.Effect<SA, SE, SR>,
|
readonly mutation: Mutation.Mutation<readonly [value: A], MA, ME, MR, MP>,
|
||||||
readonly initialSubmitProgress: SP,
|
|
||||||
readonly autosubmit: boolean,
|
readonly autosubmit: boolean,
|
||||||
readonly debounce: Option.Option<Duration.DurationInput>,
|
readonly debounce: Option.Option<Duration.DurationInput>,
|
||||||
|
|
||||||
readonly fieldCacheRef: Ref.Ref<HashMap.HashMap<FormFieldKey, FormField<unknown, unknown>>>,
|
readonly value: SubscriptionRef.SubscriptionRef<Option.Option<A>>,
|
||||||
readonly valueRef: SubscriptionRef.SubscriptionRef<Option.Option<A>>,
|
readonly encodedValue: SubscriptionRef.SubscriptionRef<I>,
|
||||||
readonly encodedValueRef: SubscriptionRef.SubscriptionRef<I>,
|
readonly error: SubscriptionRef.SubscriptionRef<Option.Option<ParseResult.ParseError>>,
|
||||||
readonly errorRef: SubscriptionRef.SubscriptionRef<Option.Option<ParseResult.ParseError>>,
|
readonly validationFiber: SubscriptionRef.SubscriptionRef<Option.Option<Fiber.Fiber<A, ParseResult.ParseError>>>,
|
||||||
readonly validationFiberRef: SubscriptionRef.SubscriptionRef<Option.Option<Fiber.Fiber<A, ParseResult.ParseError>>>,
|
|
||||||
readonly submitResultRef: SubscriptionRef.SubscriptionRef<Result.Result<SA, SE, SP>>,
|
|
||||||
|
|
||||||
readonly canSubmitSubscribable: Subscribable.Subscribable<boolean>,
|
readonly runSemaphore: Effect.Semaphore,
|
||||||
|
readonly fieldCache: Ref.Ref<HashMap.HashMap<FormFieldKey, FormField<unknown, unknown>>>,
|
||||||
) {
|
) {
|
||||||
super()
|
super()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get canSubmit(): Subscribable.Subscribable<boolean> {
|
||||||
|
return Subscribable.map(
|
||||||
|
Subscribable.zipLatestAll(this.value, this.error, this.validationFiber, this.mutation.result),
|
||||||
|
([value, error, validationFiber, submitResult]) => (
|
||||||
|
Option.isSome(value) &&
|
||||||
|
Option.isNone(error) &&
|
||||||
|
Option.isNone(validationFiber) &&
|
||||||
|
!(Result.isRunning(submitResult) || Result.isRefreshing(submitResult))
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
get submit(): Effect.Effect<Option.Option<Result.Final<MA, ME, MP>>, Cause.NoSuchElementException> {
|
||||||
|
return Effect.whenEffect(
|
||||||
|
this.value.pipe(
|
||||||
|
Effect.andThen(identity),
|
||||||
|
Effect.andThen(value => this.mutation.mutate([value])),
|
||||||
|
Effect.tap(result => Result.isFailure(result)
|
||||||
|
? Option.match(
|
||||||
|
Chunk.findFirst(
|
||||||
|
Cause.failures(result.cause as Cause.Cause<ParseResult.ParseError>),
|
||||||
|
e => e._tag === "ParseError",
|
||||||
|
),
|
||||||
|
{
|
||||||
|
onSome: e => Ref.set(this.error, Option.some(e)),
|
||||||
|
onNone: () => Effect.void,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
: Effect.void
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
this.canSubmit.get,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const isForm = (u: unknown): u is Form<unknown, unknown, unknown, unknown, unknown, unknown> => Predicate.hasProperty(u, FormTypeId)
|
export const isForm = (u: unknown): u is Form<unknown, unknown, unknown, unknown, unknown, unknown> => Predicate.hasProperty(u, FormTypeId)
|
||||||
|
|
||||||
export namespace make {
|
export namespace make {
|
||||||
export interface Options<in out A, in out I, in out R, in out SA = void, in out SE = A, out SR = never, in out SP = never> {
|
export interface Options<in out A, in out MA, in out I = A, in out R = never, in out ME = never, in out MR = never, in out MP = never> {
|
||||||
readonly schema: Schema.Schema<A, I, R>
|
readonly schema: Schema.Schema<A, I, R>
|
||||||
readonly initialEncodedValue: NoInfer<I>
|
readonly initialEncodedValue: NoInfer<I>
|
||||||
readonly onSubmit: (
|
readonly onSubmit: (
|
||||||
@@ -82,12 +116,9 @@ export const make = Effect.fnUntraced(function* <A, I = A, R = never, SA = void,
|
|||||||
const valueRef = yield* SubscriptionRef.make(Option.none<A>())
|
const valueRef = yield* SubscriptionRef.make(Option.none<A>())
|
||||||
const errorRef = yield* SubscriptionRef.make(Option.none<ParseResult.ParseError>())
|
const errorRef = yield* SubscriptionRef.make(Option.none<ParseResult.ParseError>())
|
||||||
const validationFiberRef = yield* SubscriptionRef.make(Option.none<Fiber.Fiber<A, ParseResult.ParseError>>())
|
const validationFiberRef = yield* SubscriptionRef.make(Option.none<Fiber.Fiber<A, ParseResult.ParseError>>())
|
||||||
const submitResultRef = yield* SubscriptionRef.make<Result.Result<SA, SE, SP>>(Result.initial())
|
|
||||||
|
|
||||||
return new FormImpl(
|
return new FormImpl(
|
||||||
options.schema,
|
options.schema,
|
||||||
options.onSubmit as any,
|
|
||||||
options.initialSubmitProgress as SP,
|
|
||||||
options.autosubmit ?? false,
|
options.autosubmit ?? false,
|
||||||
Option.fromNullable(options.debounce),
|
Option.fromNullable(options.debounce),
|
||||||
|
|
||||||
@@ -96,97 +127,52 @@ export const make = Effect.fnUntraced(function* <A, I = A, R = never, SA = void,
|
|||||||
yield* SubscriptionRef.make(options.initialEncodedValue),
|
yield* SubscriptionRef.make(options.initialEncodedValue),
|
||||||
errorRef,
|
errorRef,
|
||||||
validationFiberRef,
|
validationFiberRef,
|
||||||
submitResultRef,
|
|
||||||
|
|
||||||
Subscribable.map(
|
|
||||||
Subscribable.zipLatestAll(valueRef, errorRef, validationFiberRef, submitResultRef),
|
|
||||||
([value, error, validationFiber, submitResult]) => (
|
|
||||||
Option.isSome(value) &&
|
|
||||||
Option.isNone(error) &&
|
|
||||||
Option.isNone(validationFiber) &&
|
|
||||||
!(Result.isRunning(submitResult) || Result.isRefreshing(submitResult))
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
export const run = <A, I, R, SA, SE, SR, SP>(
|
export const run = <A, MA, I, R, ME, MR, MP>(
|
||||||
self: Form<A, I, R, SA, SE, SR, SP>
|
self: Form<A, MA, I, R, ME, MR, MP>
|
||||||
): Effect.Effect<void, never, Scope.Scope | R | SR> => Stream.runForEach(
|
): Effect.Effect<void> => {
|
||||||
self.encodedValueRef.changes.pipe(
|
const _self = self as FormImpl<A, MA, I, R, ME, MR, MP>
|
||||||
Option.isSome(self.debounce) ? Stream.debounce(self.debounce.value) : identity
|
return _self.runSemaphore.withPermits(1)(Stream.runForEach(
|
||||||
),
|
_self.encodedValue.changes.pipe(
|
||||||
|
Option.isSome(self.debounce) ? Stream.debounce(self.debounce.value) : identity
|
||||||
|
),
|
||||||
|
|
||||||
encodedValue => self.validationFiberRef.pipe(
|
encodedValue => _self.validationFiber.pipe(
|
||||||
Effect.andThen(Option.match({
|
Effect.andThen(Option.match({
|
||||||
onSome: Fiber.interrupt,
|
onSome: Fiber.interrupt,
|
||||||
onNone: () => Effect.void,
|
onNone: () => Effect.void,
|
||||||
})),
|
})),
|
||||||
Effect.andThen(
|
Effect.andThen(
|
||||||
Effect.forkScoped(Effect.onExit(
|
Effect.forkScoped(Effect.onExit(
|
||||||
Schema.decode(self.schema, { errors: "all" })(encodedValue),
|
Schema.decode(_self.schema, { errors: "all" })(encodedValue),
|
||||||
exit => Effect.andThen(
|
exit => Effect.andThen(
|
||||||
Exit.matchEffect(exit, {
|
Exit.matchEffect(exit, {
|
||||||
onSuccess: v => Effect.andThen(
|
onSuccess: v => Effect.andThen(
|
||||||
Ref.set(self.valueRef, Option.some(v)),
|
Ref.set(_self.value, Option.some(v)),
|
||||||
Ref.set(self.errorRef, Option.none()),
|
Ref.set(_self.error, Option.none()),
|
||||||
),
|
),
|
||||||
onFailure: c => Option.match(Chunk.findFirst(Cause.failures(c), e => e._tag === "ParseError"), {
|
onFailure: c => Option.match(Chunk.findFirst(Cause.failures(c), e => e._tag === "ParseError"), {
|
||||||
onSome: e => Ref.set(self.errorRef, Option.some(e)),
|
onSome: e => Ref.set(_self.error, Option.some(e)),
|
||||||
onNone: () => Effect.void,
|
onNone: () => Effect.void,
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
}),
|
Ref.set(_self.validationFiber, Option.none()),
|
||||||
Ref.set(self.validationFiberRef, Option.none()),
|
),
|
||||||
),
|
)).pipe(
|
||||||
)).pipe(
|
Effect.tap(fiber => Ref.set(_self.validationFiber, Option.some(fiber))),
|
||||||
Effect.tap(fiber => Ref.set(self.validationFiberRef, Option.some(fiber))),
|
Effect.andThen(Fiber.join),
|
||||||
Effect.andThen(Fiber.join),
|
Effect.andThen(() => self.autosubmit
|
||||||
Effect.andThen(() => self.autosubmit
|
? Effect.asVoid(Effect.forkScoped(submit(self)))
|
||||||
? Effect.asVoid(Effect.forkScoped(submit(self)))
|
: Effect.void
|
||||||
: Effect.void
|
),
|
||||||
),
|
Effect.forkScoped,
|
||||||
Effect.forkScoped,
|
)
|
||||||
)
|
),
|
||||||
),
|
),
|
||||||
),
|
))
|
||||||
)
|
}
|
||||||
|
|
||||||
export const submit = <A, I, R, SA, SE, SR, SP>(
|
|
||||||
self: Form<A, I, R, SA, SE, SR, SP>
|
|
||||||
): Effect.Effect<
|
|
||||||
Option.Option<Result.Result<SA, SE, SP>>,
|
|
||||||
NoSuchElementException,
|
|
||||||
Scope.Scope | SR
|
|
||||||
> => Effect.whenEffect(
|
|
||||||
self.valueRef.pipe(
|
|
||||||
Effect.andThen(identity),
|
|
||||||
Effect.andThen(value => Result.unsafeForkEffect(
|
|
||||||
self.onSubmit(value),
|
|
||||||
{ initialProgress: self.initialSubmitProgress },
|
|
||||||
)),
|
|
||||||
Effect.andThen(([sub]) => Effect.all([Effect.succeed(sub), sub.get])),
|
|
||||||
Effect.andThen(([sub, initial]) => Stream.runFoldEffect(
|
|
||||||
sub.changes,
|
|
||||||
initial,
|
|
||||||
(_, result) => Effect.as(Ref.set(self.submitResultRef, result), result),
|
|
||||||
)),
|
|
||||||
Effect.tap(result => Result.isFailure(result)
|
|
||||||
? Option.match(
|
|
||||||
Chunk.findFirst(
|
|
||||||
Cause.failures(result.cause as Cause.Cause<ParseResult.ParseError>),
|
|
||||||
e => e._tag === "ParseError",
|
|
||||||
),
|
|
||||||
{
|
|
||||||
onSome: e => Ref.set(self.errorRef, Option.some(e)),
|
|
||||||
onNone: () => Effect.void,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
: Effect.void
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
self.canSubmitSubscribable.get,
|
|
||||||
)
|
|
||||||
|
|
||||||
export namespace service {
|
export namespace service {
|
||||||
export interface Options<in out A, in out I, in out R, in out SA = void, in out SE = A, out SR = never, in out SP = never>
|
export interface Options<in out A, in out I, in out R, in out SA = void, in out SE = A, out SR = never, in out SP = never>
|
||||||
@@ -228,11 +214,11 @@ export interface FormField<in out A, in out I = A>
|
|||||||
extends Pipeable.Pipeable {
|
extends Pipeable.Pipeable {
|
||||||
readonly [FormFieldTypeId]: FormFieldTypeId
|
readonly [FormFieldTypeId]: FormFieldTypeId
|
||||||
|
|
||||||
readonly valueSubscribable: Subscribable.Subscribable<Option.Option<A>, NoSuchElementException>
|
readonly value: Subscribable.Subscribable<Option.Option<A>, Cause.NoSuchElementException>
|
||||||
readonly encodedValueRef: SubscriptionRef.SubscriptionRef<I>
|
readonly encodedValue: SubscriptionRef.SubscriptionRef<I>
|
||||||
readonly issuesSubscribable: Subscribable.Subscribable<readonly ParseResult.ArrayFormatterIssue[]>
|
readonly issues: Subscribable.Subscribable<readonly ParseResult.ArrayFormatterIssue[]>
|
||||||
readonly isValidatingSubscribable: Subscribable.Subscribable<boolean>
|
readonly isValidating: Subscribable.Subscribable<boolean>
|
||||||
readonly isSubmittingSubscribable: Subscribable.Subscribable<boolean>
|
readonly isSubmitting: Subscribable.Subscribable<boolean>
|
||||||
}
|
}
|
||||||
|
|
||||||
class FormFieldImpl<in out A, in out I = A>
|
class FormFieldImpl<in out A, in out I = A>
|
||||||
@@ -240,11 +226,11 @@ extends Pipeable.Class() implements FormField<A, I> {
|
|||||||
readonly [FormFieldTypeId]: FormFieldTypeId = FormFieldTypeId
|
readonly [FormFieldTypeId]: FormFieldTypeId = FormFieldTypeId
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
readonly valueSubscribable: Subscribable.Subscribable<Option.Option<A>, NoSuchElementException>,
|
readonly value: Subscribable.Subscribable<Option.Option<A>, Cause.NoSuchElementException>,
|
||||||
readonly encodedValueRef: SubscriptionRef.SubscriptionRef<I>,
|
readonly encodedValue: SubscriptionRef.SubscriptionRef<I>,
|
||||||
readonly issuesSubscribable: Subscribable.Subscribable<readonly ParseResult.ArrayFormatterIssue[]>,
|
readonly issues: Subscribable.Subscribable<readonly ParseResult.ArrayFormatterIssue[]>,
|
||||||
readonly isValidatingSubscribable: Subscribable.Subscribable<boolean>,
|
readonly isValidating: Subscribable.Subscribable<boolean>,
|
||||||
readonly isSubmittingSubscribable: Subscribable.Subscribable<boolean>,
|
readonly isSubmitting: Subscribable.Subscribable<boolean>,
|
||||||
) {
|
) {
|
||||||
super()
|
super()
|
||||||
}
|
}
|
||||||
@@ -268,25 +254,28 @@ class FormFieldKey implements Equal.Equal {
|
|||||||
export const isFormField = (u: unknown): u is FormField<unknown, unknown> => Predicate.hasProperty(u, FormFieldTypeId)
|
export const isFormField = (u: unknown): u is FormField<unknown, unknown> => Predicate.hasProperty(u, FormFieldTypeId)
|
||||||
const isFormFieldKey = (u: unknown): u is FormFieldKey => Predicate.hasProperty(u, FormFieldKeyTypeId)
|
const isFormFieldKey = (u: unknown): u is FormFieldKey => Predicate.hasProperty(u, FormFieldKeyTypeId)
|
||||||
|
|
||||||
export const makeFormField = <A, I, R, SA, SE, SR, SP, const P extends PropertyPath.Paths<NoInfer<I>>>(
|
export const makeFormField = <A, MA, I, R, ME, MR, MP, const P extends PropertyPath.Paths<NoInfer<I>>>(
|
||||||
self: Form<A, I, R, SA, SE, SR, SP>,
|
self: Form<A, MA, I, R, ME, MR, MP>,
|
||||||
path: P,
|
path: P,
|
||||||
): FormField<PropertyPath.ValueFromPath<A, P>, PropertyPath.ValueFromPath<I, P>> => new FormFieldImpl(
|
): FormField<PropertyPath.ValueFromPath<A, P>, PropertyPath.ValueFromPath<I, P>> => {
|
||||||
Subscribable.mapEffect(self.valueRef, Option.match({
|
const _self = self as FormImpl<A, MA, I, R, ME, MR, MP>
|
||||||
onSome: v => Option.map(PropertyPath.get(v, path), Option.some),
|
return new FormFieldImpl(
|
||||||
onNone: () => Option.some(Option.none()),
|
Subscribable.mapEffect(_self.value, Option.match({
|
||||||
})),
|
onSome: v => Option.map(PropertyPath.get(v, path), Option.some),
|
||||||
SubscriptionSubRef.makeFromPath(self.encodedValueRef, path),
|
onNone: () => Option.some(Option.none()),
|
||||||
Subscribable.mapEffect(self.errorRef, Option.match({
|
})),
|
||||||
onSome: flow(
|
SubscriptionSubRef.makeFromPath(_self.encodedValue, path),
|
||||||
ParseResult.ArrayFormatter.formatError,
|
Subscribable.mapEffect(_self.error, Option.match({
|
||||||
Effect.map(Array.filter(issue => PropertyPath.equivalence(issue.path, path))),
|
onSome: flow(
|
||||||
),
|
ParseResult.ArrayFormatter.formatError,
|
||||||
onNone: () => Effect.succeed([]),
|
Effect.map(Array.filter(issue => PropertyPath.equivalence(issue.path, path))),
|
||||||
})),
|
),
|
||||||
Subscribable.map(self.validationFiberRef, Option.isSome),
|
onNone: () => Effect.succeed([]),
|
||||||
Subscribable.map(self.submitResultRef, result => Result.isRunning(result) || Result.isRefreshing(result)),
|
})),
|
||||||
)
|
Subscribable.map(_self.validationFiber, Option.isSome),
|
||||||
|
Subscribable.map(_self.mutation.result, result => Result.isRunning(result) || Result.isRefreshing(result)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export namespace useInput {
|
export namespace useInput {
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ extends Pipeable.Class() implements Query<K, A, E, R, P> {
|
|||||||
readonly latestKey: SubscriptionRef.SubscriptionRef<Option.Option<K>>,
|
readonly latestKey: SubscriptionRef.SubscriptionRef<Option.Option<K>>,
|
||||||
readonly fiber: SubscriptionRef.SubscriptionRef<Option.Option<Fiber.Fiber<A, E>>>,
|
readonly fiber: SubscriptionRef.SubscriptionRef<Option.Option<Fiber.Fiber<A, E>>>,
|
||||||
readonly result: SubscriptionRef.SubscriptionRef<Result.Result<A, E, P>>,
|
readonly result: SubscriptionRef.SubscriptionRef<Result.Result<A, E, P>>,
|
||||||
|
|
||||||
|
readonly runSemaphore: Effect.Semaphore,
|
||||||
) {
|
) {
|
||||||
super()
|
super()
|
||||||
}
|
}
|
||||||
@@ -160,6 +162,8 @@ export const make = Effect.fnUntraced(function* <K extends readonly any[], A, E
|
|||||||
yield* SubscriptionRef.make(Option.none<K>()),
|
yield* SubscriptionRef.make(Option.none<K>()),
|
||||||
yield* SubscriptionRef.make(Option.none<Fiber.Fiber<A, E>>()),
|
yield* SubscriptionRef.make(Option.none<Fiber.Fiber<A, E>>()),
|
||||||
yield* SubscriptionRef.make(Result.initial<A, E, P>()),
|
yield* SubscriptionRef.make(Result.initial<A, E, P>()),
|
||||||
|
|
||||||
|
yield* Effect.makeSemaphore(1),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -183,5 +187,6 @@ export const run = <K extends readonly any[], A, E, R, P>(
|
|||||||
Effect.andThen(_self.start(key)),
|
Effect.andThen(_self.start(key)),
|
||||||
Effect.andThen(sub => Effect.forkScoped(_self.watch(sub))),
|
Effect.andThen(sub => Effect.forkScoped(_self.watch(sub))),
|
||||||
Effect.provide(_self.context),
|
Effect.provide(_self.context),
|
||||||
|
_self.runSemaphore.withPermits(1),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user