I create a goroutine, how can i pause in the goroutine? got some question for time.Sleep

646 views
Skip to first unread message

singochina

unread,
May 31, 2011, 3:00:41 AM5/31/11
to golang-nuts
Dera All,

I got a problem, my coding was below:

func yoyo() {
for true {
//TODO something
time.Sleep(3000)
}
}

func main() {
go yoyo()

//In here i begin a http server
}


I found my goroutine does not pause in the sleep position, is it the
coding got some problem as there?

Regards,
Singo

Steven

unread,
May 31, 2011, 3:05:59 AM5/31/11
to singochina, golang-nuts

If you're running it on the go playground, it's because time doesn't
actually work there. Otherwise, what do you mean by "it does not pause
in the Sleep position"? How long do you want it to pause for? What is
happening instead?

chris dollin

unread,
May 31, 2011, 3:10:28 AM5/31/11
to singochina, golang-nuts

3000 nanoseconds is 3 millionths of a second. How can you
tell that yoyo didn't pause?

--
Chris "allusive" Dollin

singochina

unread,
May 31, 2011, 3:16:53 AM5/31/11
to golang-nuts
Hi,

Actually i want to do somthing in "//TODO something", and i wanna do
that each 3 second.

On May 31, 3:05 pm, Steven <steven...@gmail.com> wrote:

singochina

unread,
May 31, 2011, 3:20:27 AM5/31/11
to golang-nuts
Hi,

So i want to 3 second is 3 * 1000 * 1000 right?

On May 31, 3:10 pm, chris dollin <ehog.he...@googlemail.com> wrote:

zhai

unread,
May 31, 2011, 3:26:23 AM5/31/11
to singochina, golang-nuts
On Tue, May 31, 2011 at 3:20 PM, singochina <singo...@gmail.com> wrote:
Hi,

So i want to 3 second is 3 * 1000 * 1000 right?

 
3 seconds = 3e9  nanoseconds 

singochina

unread,
May 31, 2011, 3:43:20 AM5/31/11
to golang-nuts
Ya, thx, the problem was solved

On May 31, 3:26 pm, zhai <qyz...@gmail.com> wrote:

Mike Rosset

unread,
May 31, 2011, 5:19:38 AM5/31/11
to singochina, golang-nuts

I found Tick also very useful for scheduling.

here is an example . https://gist.github.com/982382

Mike

Reply all
Reply to author
Forward
0 new messages