Last active
September 20, 2023 17:43
-
-
Save apmckinlay/1d4eb7b5489cdff0e0c5a00a9eee9dee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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