MCPcopy Create free account
hub / github.com/Effect-TS/effect / makeUsers

Function makeUsers

packages/effect/test/ui/QueryRuns.test.ts:37–60  ·  view source on GitHub ↗
(staleTime: Duration.Input = "30 seconds")

Source from the content-addressed store, hash-verified

35
36// A query whose fetcher takes 10 ms and returns what the server holds.
37const makeUsers = (staleTime: Duration.Input = "30 seconds") => {
38 const db = { calls: 0, name: "Ann", fail: false }
39 class GetUser extends Query.Service<GetUser>()(
40 "users/GetUser",
41 {
42 args: { id: Schema.String },
43 success: User,
44 error: Schema.String,
45 staleTime
46 }
47 ) {
48 static readonly layer = this.toLayer(Effect.fnUntraced(function*({ id }) {
49 db.calls++
50 yield* Effect.sleep(10)
51 if (db.fail) return yield* Effect.fail("nope")
52 return { id, name: db.name }
53 }))
54 }
55 return {
56 db,
57 GetUser,
58 provide: Effect.provide(Layer.merge(GetUser.layer, TestQuery.layer()))
59 }
60}
61
62const makeCount = (staleTime: Duration.Input = "30 seconds") => {
63 const db = { calls: 0, count: 0 }

Callers 1

QueryRuns.test.tsFile · 0.70

Calls 3

mergeMethod · 0.65
provideMethod · 0.45
layerMethod · 0.45

Tested by

no test coverage detected