| 178 | const router = Router(InvRsc)({ |
| 179 | dependencies: [RepoItems.Default, OtherItems.Default], |
| 180 | *effect(match) { |
| 181 | const repo = yield* RepoItems |
| 182 | const otherRepo = yield* OtherItems |
| 183 | return match({ |
| 184 | DoNothing: () => Effect.void, |
| 185 | DoWithDynamicKey: Effect.fnUntraced(function*() { |
| 186 | yield* Invalidation.InvalidationSet.use((_) => _.add(DynamicKey)) |
| 187 | return "done" |
| 188 | }), |
| 189 | DoWithBothKeys: Effect.fnUntraced(function*() { |
| 190 | yield* Invalidation.InvalidationSet.use((_) => _.add(DynamicKey)) |
| 191 | yield* Invalidation.InvalidationSet.use((_) => _.add(ExtraKey)) |
| 192 | return 99 |
| 193 | }), |
| 194 | DoAndFail: Effect.fnUntraced(function*() { |
| 195 | yield* Invalidation.InvalidationSet.use((_) => _.add(DynamicKey)) |
| 196 | return yield* Effect.fail(new CmdBoom({ reason: "intentional failure" })) |
| 197 | }), |
| 198 | StreamWithKey: () => |
| 199 | Stream.fromIterable([1, 2, 3]).pipe( |
| 200 | Stream.tap(() => Invalidation.InvalidationSet.use((_) => _.add(StreamKey))) |
| 201 | ), |
| 202 | StreamWithRepoWrite: () => |
| 203 | Stream.fromIterable([1, 2, 3]).pipe( |
| 204 | Stream.tap((n) => repo.save(new RepoItem({ id: String(n), label: "x" })).pipe(Effect.orDie)) |
| 205 | ), |
| 206 | GetRepoCount: () => repo.all.pipe(Effect.map((_) => _.length), Effect.orDie), |
| 207 | SaveRepoItem: ({ id, label }) => repo.save(new RepoItem({ id, label })).pipe(Effect.orDie), |
| 208 | SaveOtherItem: ({ id, label }) => otherRepo.save(new OtherItem({ id, label })).pipe(Effect.orDie) |
| 209 | }) |
| 210 | } |
| 211 | }) |
| 212 | |
| 213 | const RpcRouterLayer = matchAll({ router }) |