Skip to content

Instantly share code, notes, and snippets.

@vgangireddyin
Created May 27, 2016 06:40
Show Gist options
  • Save vgangireddyin/f39f5bb089529383cf8a57d2becb63c6 to your computer and use it in GitHub Desktop.
Save vgangireddyin/f39f5bb089529383cf8a57d2becb63c6 to your computer and use it in GitHub Desktop.
Go Routine
package main
import(
"fmt"
"time"
)
func Publish(text string, delay time.Duration) {
/**
* Create a thread at os level and shedule by go sheduler
*/
go func() {
time.Sleep(delay)
fmt.Println("Latest News:", text)
}()
}
func main() {
Publish("some random note", 5*time.Second)
fmt.Println("this may publish before latest one")
time.Sleep(10*time.Second)
fmt.Println("After 10 Sec: final act")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment