// 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);