Skip to content

Instantly share code, notes, and snippets.

@apmckinlay
Last active September 20, 2023 17:43
Show Gist options
  • Save apmckinlay/1d4eb7b5489cdff0e0c5a00a9eee9dee to your computer and use it in GitHub Desktop.
Save apmckinlay/1d4eb7b5489cdff0e0c5a00a9eee9dee to your computer and use it in GitHub Desktop.
timer := time.NewTimer(timeout)
for {
select {
case task = <-ws.ch:
if !timer.Stop() {
<-timer.C
}
timer.Reset(timeout)
run(task)
case <-timer.C:
return // idle timeout, worker terminates
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment