Problems? Is your data what you think it is? | |
PerlMonks |
Re: Perl6: react/whenever timeoutby moritz (Cardinal) |
on Jul 21, 2016 at 20:57 UTC ( [id://1168273]=note: print w/replies, xml ) | Need Help?? |
Concurrency is not my big strength, so this will likely turn out to be a bit more clunky than necessary. One possible trick is to use the Promise.anyof combinator to get the first of the timeout or the actual receiving action:
This puts a timeout on every individual .receive, but finishes early if a value is available earlier. It's also not a busy loop, so doesn't use much CPU. I'm sure there are much more elegant solutions out there if you use a supply instead of a channel to generate the values; maybe some of the promise combinators like zip-latest can be used then.
In Section
Seekers of Perl Wisdom
|
|