Effect CommunityEC
Effect Community2y ago
30 replies
David Golightly

Effect.race with acquireRelease

I’m using acquireRelease to open (acquire) and close (release) a WebSocket connection. While this connection is live, I want to send a keepalive heartbeat message every 5 seconds, until the connection is closed. I have this mostly set up with a scheduler as an argument to Effect.race(scheduler, SocketEffect) but I’m observing that the scheduler ends when the connection opens (after acquire succeeds), not when it closes (after release). This makes sense, naively, but I’m curious how to go about implementing the behavior I want.

What I think I’m looking for here is (somehow) an effect that succeeds when a given scope is closed, but I’m not really sure what incantation of tools would do the trick. Thanks in advance!
Was this page helpful?