New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wait Timeouts and Message Expirations for Channels #2
Comments
To check directly if there's any message on channel, the client would just call: let message = null
try {
message = await sporadicChannels.receive(channel, 0)
} catch (reason) {
// handles the case of empty channel here...
}
UPDATE: sporadic/__tests__/channels-plus.js Line 15 in 358f88f
|
Signed-off-by: Marco Aurélio da Silva <marcoonroad@gmail.com>
Signed-off-by: Marco Aurélio da Silva <marcoonroad@gmail.com>
…future (see issue #2) Signed-off-by: Marco Aurélio da Silva <marcoonroad@gmail.com>
BUMP: Additional APIs provided: const wasReceived = await channels.sendAfter(delayA, channel, msg, expiration)
...
const msg = await channels.receiveAfter(delayB, channel, timeout) Both functions trigger their respective immediate counterparts scheduled on the future. Internally it's a |
To avoid blocking forever (while waiting for a message) and to provide a mechanism resembling a cache, timeouts and expirations are good abstractions over channels. The API will be the following, thus:
Where
timeout
is optional, and:Where
expiration
is optional too. Thereceive
operation will fail/throw a Timeout error whenever a timeout occurs. For the case ofsend
, it doesn't fails/throws (as is the case ofreceive
), butwasReceived
will be false whenever theexpiration
triggers and the message is erased (and thus, not received). Bothtimeout
andexpiration
are units of time at ms (units compatible with JavaScript'ssetTimeout
andsetInterval
).Further discussions about implementation tradeoffs may be needed, but this API sketch is clean enough to not be changed later.
The text was updated successfully, but these errors were encountered: