Files
effect/bundle/schema-string-async.ts
T
2025-06-27 16:34:40 +12:00

22 lines
642 B
TypeScript

import * as Duration from "#dist/effect/Duration"
import * as Effect from "#dist/effect/Effect"
import * as Result from "#dist/effect/Result"
import * as Schema from "#dist/effect/schema/Schema"
import * as Transformation from "#dist/effect/schema/Transformation"
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: Result.ok
})
))
Schema.decodeUnknownEffect(schema)({ a: "a", b: 1, c: ["c"] }).pipe(
Effect.runFork
)