Skip to content

Instantly share code, notes, and snippets.

@andrewchambers
Created July 14, 2014 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewchambers/31b801d5bc1f9d222839 to your computer and use it in GitHub Desktop.
Save andrewchambers/31b801d5bc1f9d222839 to your computer and use it in GitHub Desktop.
example
package main
import (
"time"
"github.com/gopherjs/gopherjs/js"
)
func main() {
c := make(chan string)
//Three concurrent infinite loops generating events
go generateEvents(1 * time.Second,"event source one", c)
go generateEvents(2 * time.Second,"event source two", c)
go generateEvents(3 * time.Second,"event source three", c)
//Forth thread displays events
displayEvents(c)
}
func generateEvents(delay time.Duration,message string,eventChan chan string) {
for {
time.Sleep(delay)
eventChan <- message
}
}
func displayEvents(eventChan chan string) {
for {
event := <- eventChan
js.Global.Call("alert", event)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment