1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 // Sleep pauses the current goroutine for at least ns nanoseconds.
13 // Higher resolution sleeping may be provided by syscall.Nanosleep
14 // on some operating systems.
15 func Sleep(ns int64) os.Error {
16 _, err := sleep(Nanoseconds(), ns)
20 // After waits at least ns nanoseconds before sending the current time
21 // on the returned channel.
22 func After(ns int64) <-chan int64 {
24 ch := make(chan int64, 1)
32 // sleep takes the current time and a duration,
33 // pauses for at least ns nanoseconds, and
34 // returns the current time and an error.
35 func sleep(t, ns int64) (int64, os.Error) {
36 // TODO(cw): use monotonic-time once it's available
39 errno := syscall.Sleep(end - t)
40 if errno != 0 && errno != syscall.EINTR {
41 return 0, os.NewSyscallError("sleep", errno)