3 ms·
Is there a select() analogue? Maybe under another name?
by mpd 9y ago
Is there a select() analogue? Maybe under another name?
- kasey_junk 9y agoThe take() function is equivalent to a bare <- channel read. the poll(time, timeunit) function is equivalent to a select with a case and a read off the done channel of a context with a timeout. The poll() function is equivalent to a select with a case and a default condition. To get the behavior of a select composed of several channels and no default case I'd have to dig into the exact behavior of the select statement in go, but it could be accomplished with a loop over if/else if/else statement where the else had a thread sleep/thread yield. I actually wrote a dsl in Scala a few years back that actually used the keyword select for this operation before I'd ever encountered golang. I used "on" instead of case but the behaviors were nearly identical.
- mpd 9y agoI assume the name came from the select syscall, maybe unconsciously in your case :) Hopefully something comes along to fill this gap officially. Channels are my favorite concurrency primitive by a huge margin. The more languages that support them, the better.
- kasey_junk 9y agoIt wasn't unintentional that I used select. The dsl actually abstracted over network operations first and I only later added queues to the abstraction.
- twic 9y agoNo. And this is certainly an annoyance at times!