Add sync mechanism
All checks were successful
Lint / lint (push) Successful in 14s

This commit is contained in:
Julien Valverdé
2026-05-02 00:35:07 +02:00
parent 441173d536
commit b6b199b2fa

View File

@@ -1,4 +1,4 @@
import { Array, type Context, Effect, Fiber, Option, ParseResult, Pipeable, Predicate, Schema, type Scope, Stream, SubscriptionRef } from "effect"
import { Array, type Context, Effect, Equal, Fiber, Option, ParseResult, Pipeable, Predicate, Schema, type Scope, Stream, SubscriptionRef } from "effect"
import * as Form from "./Form.js"
import * as Lens from "./Lens.js"
import * as Subscribable from "./Subscribable.js"
@@ -148,36 +148,25 @@ export class SynchronizedFormImpl<
}
get run(): Effect.Effect<void, TER> {
return Effect.void
// return this.runSemaphore.withPermits(1)(Effect.provide(
// Effect.andThen(
// Effect.flatMap(
// Lens.get(this.internalEncodedValue),
// encodedValue => this.synchronizeEncodedValue(encodedValue),
// ),
// Stream.runForEach(
// Stream.drop(this.target.changes, 1),
// targetValue => Schema.encode(this.schema, { errors: "all" })(targetValue).pipe(
// Effect.flatMap(encodedValue => Effect.andThen(
// Effect.whenEffect(
// Lens.set(this.internalEncodedValue, encodedValue),
// Effect.map(
// Lens.get(this.internalEncodedValue),
// currentEncodedValue => !Equal.equals(encodedValue, currentEncodedValue),
// ),
// ),
// Effect.andThen(
// Lens.set(this.issues, Array.empty()),
// ),
// )),
// Effect.ignore,
// ),
// ),
// ),
// this.context,
// ))
return this.runSemaphore.withPermits(1)(Effect.provide(
Stream.runForEach(
Stream.drop(this.target.changes, 1),
targetValue => Schema.encode(this.schema, { errors: "all" })(targetValue).pipe(
Effect.flatMap(encodedValue => Effect.andThen(
Effect.whenEffect(
Lens.set(this.internalEncodedValue, encodedValue),
Effect.map(
Lens.get(this.internalEncodedValue),
currentEncodedValue => !Equal.equals(encodedValue, currentEncodedValue),
),
),
Lens.set(this.issues, Array.empty()),
)),
Effect.ignore,
),
),
this.context,
))
}
}