select timeout

10 views
Skip to first unread message

Michael Hoisie

unread,
Dec 18, 2009, 4:18:46 PM12/18/09
to golang-nuts
I noticed that select doesn't have a timeout mechanism. What's the
best way to add one?

In my scenario I'm running a few processes on goroutines, and using a
blocking select to wait for all of them to finish. However, the
processes might take a long time to complete, and I'd like to have a
timeout on the select call. I could have a separate goroutine that
sends heartbeat signals, but that seems like a lot of work.

In the traditional unix select, there's a timeout argument. Would that
be something useful to add to the language?

Ian Lance Taylor

unread,
Dec 18, 2009, 4:25:09 PM12/18/09
to Michael Hoisie, golang-nuts
Michael Hoisie <hoi...@gmail.com> writes:

A select timeout may be useful.

In the meantime the heartbeat signal generator has already been
written for you: time.Tick returns a channel that you can use in
select.

Ian

Reply all
Reply to author
Forward
0 new messages