diff --git a/packages/effect-fc/src/SubmittableForm.ts b/packages/effect-fc/src/SubmittableForm.ts index f7309da..048e59e 100644 --- a/packages/effect-fc/src/SubmittableForm.ts +++ b/packages/effect-fc/src/SubmittableForm.ts @@ -21,6 +21,7 @@ extends Form.Form { > readonly validationFiber: Subscribable.Subscribable>, never, never> + readonly run: Effect.Effect readonly submit: Effect.Effect>, Cause.NoSuchElementException> } @@ -130,6 +131,13 @@ extends Pipeable.Class() implements SubmittableForm { ) } + get run(): Effect.Effect { + return Lens.get(this.encodedValue).pipe( + Effect.flatMap(v => this.synchronizeEncodedValue(v)), + this.runSemaphore.withPermits(1), + ) + } + get submit(): Effect.Effect>, Cause.NoSuchElementException, never> { return Lens.get(this.value).pipe( Effect.flatMap(identity), @@ -197,3 +205,19 @@ export const make = Effect.fnUntraced(function* + extends make.Options {} +} + +export const service = ( + options: service.Options +): Effect.Effect< + SubmittableForm, MP>, + never, + Scope.Scope | R | Result.forkEffect.OutputContext +> => Effect.tap( + make(options), + form => Effect.forkScoped(form.run), +)