Files
effect/bundle/schema-string-async.ts
T
2025-07-18 22:39:10 +12:00

21 lines
616 B
TypeScript

import * as Effect from "#dist/effect/Effect"
import * as Schema from "#dist/effect/schema/Schema"
import * as Transformation from "#dist/effect/schema/Transformation"
import * as Duration from "#dist/effect/time/Duration"
const schema = Schema.String.pipe(Schema.decodeTo(
Schema.String,
Transformation.transformOrFail({
decode: (s) =>
Effect.gen(function*() {
yield* Effect.clockWith((clock) => clock.sleep(Duration.millis(300)))
return s
}),
encode: (_) => Effect.succeed(_)
})
))
Schema.decodeUnknownEffect(schema)({ a: "a", b: 1, c: ["c"] }).pipe(
Effect.runFork
)