I have a forked fiber that needs to call a repository method, but the method hangs and never completes. Here's the setup:
// In battle-screen-coordinator.ts, I create a runtime with all layers const fullLayer = Layer.mergeAll( repositoryLayer, RpcClientLive, LoggerServiceLive, ); runtime = ManagedRuntime.make(fullLayer); // Later, I call startPolling and provide the repository layer yield* pollingController .startPolling({ battleId, requestingUserId: playerId, onTurnChange: (battleState) => Effect.gen(function* () { // handle turn change }), }) .pipe(Effect.provide(repositoryLayer)); // In polling-controller.ts, I get the repository before forking const repository = yield* BattleRepository; const pollingEffect = Effect.gen(function* () { while (true) { // This call hangs and never completes: const battleState = yield* repository.getBattleState({ battleId, requestingUserId, }); yield* Effect.sleep(Duration.millis(2000)); } }); const fiber = yield* Effect.forkDaemon(pollingEffect);
// In battle-screen-coordinator.ts, I create a runtime with all layers const fullLayer = Layer.mergeAll( repositoryLayer, RpcClientLive, LoggerServiceLive, ); runtime = ManagedRuntime.make(fullLayer); // Later, I call startPolling and provide the repository layer yield* pollingController .startPolling({ battleId, requestingUserId: playerId, onTurnChange: (battleState) => Effect.gen(function* () { // handle turn change }), }) .pipe(Effect.provide(repositoryLayer)); // In polling-controller.ts, I get the repository before forking const repository = yield* BattleRepository; const pollingEffect = Effect.gen(function* () { while (true) { // This call hangs and never completes: const battleState = yield* repository.getBattleState({ battleId, requestingUserId, }); yield* Effect.sleep(Duration.millis(2000)); } }); const fiber = yield* Effect.forkDaemon(pollingEffect);
The
repository.getBattleState()
repository.getBattleState()
returns
Effect.Effect<BattleState, Error, GameRpcClient>
Effect.Effect<BattleState, Error, GameRpcClient>
- it needs the
GameRpcClient
GameRpcClient
layer to run.
Question: How do I ensure the forked fiber has access to all the necessary layers (especially GameRpcClient) so that the repository method can complete?