本文整理汇总了Golang中syscall.Sleep函数的典型用法代码示例。如果您正苦于以下问题:Golang Sleep函数的具体用法?Golang Sleep怎么用?Golang Sleep使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Sleep函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
sio := socketio.NewSocketIO(nil)
sio.OnConnect(func(c *socketio.Conn) {
sio.Broadcast("connected: socket.io/" + c.String())
})
sio.OnDisconnect(func(c *socketio.Conn) {
sio.BroadcastExcept(c, "disconnected: socket.io/"+c.String())
})
sio.OnMessage(func(c *socketio.Conn, msg socketio.Message) {
sio.BroadcastExcept(c, msg.Data())
})
go func() {
count := 0
for {
sio.Broadcast(fmt.Sprintf("ping%d", count))
count++
syscall.Sleep(1e9)
}
}()
mux := sio.ServeMux()
mux.Handle("/", http.FileServer("www/", "/"))
if err := http.ListenAndServe(":8080", mux); err != nil {
fmt.Println("ListenAndServe:", err)
}
}
示例2: sysSleep
func sysSleep(t int64) os.Error {
err := syscall.Sleep(t)
if err != nil {
return os.NewSyscallError("sleep", err)
}
return nil
}
示例3: Backup
func (db *Database) Backup(p BackupParameters) (r Reporter, e os.Error) {
if target, e := Open(p.Target); e == nil {
if backup, e := NewBackup(target, "main", db, "main"); e == nil && p.PagesPerStep > 0 {
r = make(Reporter, p.QueueLength)
go func() {
defer target.Close()
defer backup.Finish()
defer close(r)
for {
report := &ProgressReport{
Source: db.Filename,
Target: p.Target,
Error: backup.Step(p.PagesPerStep),
Total: backup.PageCount(),
Remaining: backup.Remaining(),
}
r <- report
if e, ok := report.Error.(Errno); ok && !(e == OK || e == BUSY || e == LOCKED) {
break
}
if p.Interval > 0 {
syscall.Sleep(p.Interval)
}
}
}()
} else {
target.Close()
e = target.Error()
}
}
return
}
示例4: monitorServices
func monitorServices() {
for {
skylib.LoadConfig()
for _, v := range skylib.NS.Services {
if (v.Port != *skylib.Port) || (v.IPAddress != *skylib.BindIP) {
portString := fmt.Sprintf("%s:%d", v.IPAddress, v.Port)
x, err := rpc.DialHTTP("tcp", portString)
if err != nil {
log.Println("BAD CON:", err)
v.RemoveFromConfig()
skylib.Errors.Add(1)
break
}
hc := skylib.HeartbeatRequest{Timestamp: time.Seconds()}
hcr := skylib.HeartbeatResponse{}
err = x.Call("Service.Ping", hc, &hcr)
if err != nil {
log.Println(err.String())
skylib.Errors.Add(1)
}
x.Close()
skylib.Requests.Add(1)
}
}
syscall.Sleep(2000 * 1000000) // sleep then do it again!
}
}
示例5: sysSleep
func sysSleep(t int64) error {
errno := syscall.Sleep(t)
if errno != 0 && errno != syscall.EINTR {
return os.NewSyscallError("sleep", errno)
}
return nil
}
示例6: gracefulShutdown
func gracefulShutdown() {
log.Println("Graceful Shutdown")
svc.RemoveFromConfig()
//would prefer to unregister HTTP and RPC handlers
//need to figure out how to do that
syscall.Sleep(10e9) // wait 10 seconds for requests to finish #HACK
syscall.Exit(0)
}
示例7: sleep
// sleep takes the current time and a duration,
// pauses for at least ns nanoseconds, and
// returns the current time and an error.
func sleep(t, ns int64) (int64, os.Error) {
// TODO(cw): use monotonic-time once it's available
end := t + ns
for t < end {
errno := syscall.Sleep(end - t)
if errno != 0 && errno != syscall.EINTR {
return 0, os.NewSyscallError("sleep", errno)
}
t = Nanoseconds()
}
return t, nil
}
示例8: monitorServices
func monitorServices() {
for {
skylib.LoadConfig()
for _, v := range skylib.NS.Services {
fmt.Println(v)
// Insert your code to do something for
// each service here
// or get rid of this loop
// and do something else interesting!
}
syscall.Sleep(2000 * 1000000) // sleep then do it again!
}
}
示例9: main
func main() {
jsx = gojs.Init()
for {
go test()
syscall.Sleep(1E9) // 1 sec pause
}
/*
js := gojs.NewContext(jsx)
gojs.SetProperty(js, "test.property", "hi");
gojs.DefineCallback(js, "test_callback", cb);
gojs.Exec(js, "test_callback({filename: 'test.wav', play: false});")
gojs.DestroyContext(js)
*/
}
示例10: monitorServices
func monitorServices() {
println("Fear the reaper...")
for {
skylib.LoadConfig()
clients := skylib.GetAllClientsByService("CommonService")
println("#Agents:", len(clients))
for _, x := range clients {
fmt.Printf("%v\n", x)
// Insert your code to do something for
// each service here
// or get rid of this loop
// and do something else interesting!
x.Close()
skylib.Requests.Add(1) // Should we count Heartbeat requests?
}
syscall.Sleep(2000 * 1000000) // sleep then do it again!
}
}
示例11: monitorServices
func monitorServices() {
println("Fear the reaper...")
for {
skylib.LoadConfig()
clients := skylib.GetAllClientsByService("CommonService")
println("#Agents:", len(clients))
for _, x := range clients {
hc := skylib.HeartbeatRequest{Timestamp: time.Seconds()}
hcr := skylib.HeartbeatResponse{}
err := x.Call("CommonService.Ping", hc, &hcr)
if err != nil {
panic(err)
}
fmt.Printf("hcr:%v\n", hcr)
x.Close()
skylib.Requests.Add(1) // Should be count Heartbeat requests?
}
syscall.Sleep(2000 * 1000000) // sleep then do it again!
}
}
示例12: main
func main() {
runtime.GOMAXPROCS(10)
gdk.ThreadsInit()
gdk.ThreadsEnter()
gtk.Init(nil)
window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
window.Connect("destroy", func() {
gtk.MainQuit()
}, nil)
vbox := gtk.VBox(false, 1)
label1 := gtk.Label("")
vbox.Add(label1)
label2 := gtk.Label("")
vbox.Add(label2)
window.Add(vbox)
window.SetSizeRequest(100, 100)
window.ShowAll()
syscall.Sleep(1000 * 1000 * 100)
go (func() {
for i := 0; i < 300000; i++ {
gdk.ThreadsEnter()
label1.SetLabel(strconv.Itoa(i))
gdk.ThreadsLeave()
}
gtk.MainQuit()
})()
go (func() {
for i := 300000; i >= 0; i-- {
gdk.ThreadsEnter()
label2.SetLabel(strconv.Itoa(i))
gdk.ThreadsLeave()
}
gtk.MainQuit()
})()
gtk.Main()
}
示例13: main
func main() {
//instantiate a new Resque
r := goresque.NewResque("127.0.0.1", 6379, 0)
for { // loop forever
//pop a job off the queue the easy way
job2, err2 := r.Reserve("flavors")
if err2 != nil {
fmt.Print(".") // makes it look very Wargams-ish
syscall.Sleep(1000000) // this is a .1 second sleep
} else {
fmt.Println("return:", job2)
switch job2.Class {
case "FlavorSaver":
is := new(FlavorSaver)
is.perform(job2.Args)
default:
fmt.Println("Incorrect Class!")
}
}
}
}
示例14: test
// Create context, wait 2 seconds, destroy it again
func test() {
js := gojs.NewContext(jsx)
syscall.Sleep(2E9)
gojs.DestroyContext(js)
}
示例15: Sleep
// Sleep pauses the current goroutine for ns nanoseconds.
// It returns os.EINTR if interrupted.
func Sleep(ns int64) os.Error {
return os.NewSyscallError("sleep", syscall.Sleep(ns))
}