Created
July 11, 2013 19:54
-
-
Save benmanns/5978665 to your computer and use it in GitHub Desktop.
This file contains 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
package main | |
import ( | |
"log" | |
"time" | |
) | |
func main() { | |
ch := make(chan int) | |
go func() { | |
for { | |
select { | |
case ch <- func() int { | |
log.Printf("reserved") | |
return 1 | |
}(): | |
default: | |
log.Printf("waited") | |
time.Sleep(1 * time.Second) | |
} | |
} | |
}() | |
time.Sleep(5 * time.Second) | |
log.Printf("got %d", <-ch) | |
} |
This file contains 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
2013/07/11 15:53:25 reserved | |
2013/07/11 15:53:25 waited | |
2013/07/11 15:53:26 reserved | |
2013/07/11 15:53:26 waited | |
2013/07/11 15:53:27 reserved | |
2013/07/11 15:53:27 waited | |
2013/07/11 15:53:28 reserved | |
2013/07/11 15:53:28 waited | |
2013/07/11 15:53:29 reserved | |
2013/07/11 15:53:29 waited | |
2013/07/11 15:53:30 reserved | |
2013/07/11 15:53:30 reserved | |
2013/07/11 15:53:30 waited | |
2013/07/11 15:53:30 got 1 |
This file contains 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
2013/07/11 15:53:25 waited | |
2013/07/11 15:53:26 waited | |
2013/07/11 15:53:27 waited | |
2013/07/11 15:53:28 waited | |
2013/07/11 15:53:29 waited | |
2013/07/11 15:53:30 reserved | |
2013/07/11 15:53:30 got 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment