(options: {
readonly staleTime: Duration.Input
readonly idleTimeToLive?: Duration.Input
readonly refetchInterval?: Query.RefetchInterval<
{ readonly id: string },
User,
string
>
readonly reactivityKeys?: (
args: { readonly id: string }
) => Reactivity.KeysInput
})
| 47 | |
| 48 | // A query whose fetcher takes 10 ms and does what `db.mode` says. |
| 49 | const makeUsers = (options: { |
| 50 | readonly staleTime: Duration.Input |
| 51 | readonly idleTimeToLive?: Duration.Input |
| 52 | readonly refetchInterval?: Query.RefetchInterval< |
| 53 | { readonly id: string }, |
| 54 | User, |
| 55 | string |
| 56 | > |
| 57 | readonly reactivityKeys?: ( |
| 58 | args: { readonly id: string } |
| 59 | ) => Reactivity.KeysInput |
| 60 | }) => { |
| 61 | const db = { |
| 62 | calls: 0, |
| 63 | name: "Ann", |
| 64 | mode: "ok" as "ok" | "fail" | "die" | "interrupt" |
| 65 | } |
| 66 | class GetUser extends Query.Service<GetUser>()( |
| 67 | "users/GetUser", |
| 68 | { |
| 69 | args: { id: Schema.String }, |
| 70 | success: User, |
| 71 | error: Schema.String, |
| 72 | tags: [Users], |
| 73 | ...options |
| 74 | } |
| 75 | ) { |
| 76 | static readonly layer = this.toLayer(Effect.fnUntraced(function*({ id }) { |
| 77 | db.calls++ |
| 78 | yield* Effect.sleep(10) |
| 79 | if (db.mode === "die") return yield* Effect.die("boom") |
| 80 | // A Fail next to an Interrupt is still a Failure, and holds only the Fail. |
| 81 | if (db.mode === "fail") { |
| 82 | return yield* Effect.failCause( |
| 83 | Cause.combine(Cause.fail("nope"), Cause.interrupt()) |
| 84 | ) |
| 85 | } |
| 86 | if (db.mode === "interrupt") return yield* Effect.interrupt |
| 87 | return { id, name: db.name } |
| 88 | })) |
| 89 | } |
| 90 | const provide = Effect.provide(Layer.merge(GetUser.layer, TestQuery.layer())) |
| 91 | return { db, GetUser, provide } |
| 92 | } |
| 93 | |
| 94 | // Watches through the public `changes` Stream, and records what it emits. |
| 95 | const watch = Effect.fnUntraced( |
no test coverage detected