Time

2477 views
Skip to first unread message

Andrew Gerrand

unread,
Dec 12, 2012, 6:47:07 PM12/12/12
to golang-nuts
http://play.golang.org/p/3fv0L3-z0s

This will make its way to golang.org, tour.golang.org, and talks.golang.org in due course.

Andrew

Glenn Brown

unread,
Dec 12, 2012, 6:50:01 PM12/12/12
to Andrew Gerrand, Glenn Brown, golang-nuts
It's about time! :-) --Glenn

--
 
 

Michael Jones

unread,
Dec 12, 2012, 6:50:12 PM12/12/12
to Andrew Gerrand, golang-nuts
Yay!

--
 
 



--
Michael T. Jones | Chief Technology Advocate  | m...@google.com |  +1 650-335-5765

Herbert Fischer

unread,
Dec 12, 2012, 6:52:05 PM12/12/12
to Andrew Gerrand, golang-nuts
clap clap clap
> --
>
>

Andrew Gerrand

unread,
Dec 12, 2012, 7:05:17 PM12/12/12
to Catalin Patulea, Michael Jones, golang-nuts
On 13 December 2012 10:53, Catalin Patulea <cata...@google.com> wrote:
I'm guessing time.Now().Second() does not advance by 1 over the course of a time.Sleep(1 * time.Second)?

It does, of course!

Brad Fitzpatrick

unread,
Dec 12, 2012, 7:08:21 PM12/12/12
to Andrew Gerrand, golang-nuts

Catalin Patulea

unread,
Dec 12, 2012, 6:53:20 PM12/12/12
to Michael Jones, Andrew Gerrand, golang-nuts
I'm guessing time.Now().Second() does not advance by 1 over the course of a time.Sleep(1 * time.Second)?

--
 
 

Catalin Patulea

unread,
Dec 12, 2012, 6:58:12 PM12/12/12
to Michael Jones, Andrew Gerrand, golang-nuts
Ahhh, the playground is in a time vortex. Of course!

Brad Fitzpatrick

unread,
Dec 12, 2012, 7:10:40 PM12/12/12
to Catalin Patulea, Michael Jones, Andrew Gerrand, golang-nuts
time.Sleeps happen instantly on the server, so there's no duration of time in which a running goroutine could observe anything.

When a Write happens, it just records the fake time and includes that in the JavaScript sent to the browser, which simulates time with JavaScript window setTimeouts.

On Wed, Dec 12, 2012 at 3:53 PM, Catalin Patulea <cata...@google.com> wrote:
--
 
 

Dave Cheney

unread,
Dec 12, 2012, 7:18:54 PM12/12/12
to Brad Fitzpatrick, Catalin Patulea, Michael Jones, Andrew Gerrand, golang-nuts
Very metaphysical.
> --
>
>

Andrew Gerrand

unread,
Dec 12, 2012, 7:20:55 PM12/12/12
to Brad Fitzpatrick, Catalin Patulea, Michael Jones, golang-nuts

On 13 December 2012 11:10, Brad Fitzpatrick <brad...@golang.org> wrote:
time.Sleeps happen instantly on the server, so there's no duration of time in which a running goroutine could observe anything.

When a Write happens, it just records the fake time and includes that in the JavaScript sent to the browser, which simulates time with JavaScript window setTimeouts.

Here are the runtime modifications, for the interested:


Andrew

Catalin Patulea

unread,
Dec 12, 2012, 7:25:15 PM12/12/12
to Andrew Gerrand, Brad Fitzpatrick, Michael Jones, golang-nuts
How was the epoch chosen? :)

David Symonds

unread,
Dec 12, 2012, 7:28:34 PM12/12/12
to Catalin Patulea, Andrew Gerrand, Brad Fitzpatrick, Michael Jones, golang-nuts
On Thu, Dec 13, 2012 at 11:25 AM, Catalin Patulea <cata...@google.com> wrote:

> How was the epoch chosen? :)

It's an exercise for the reader.

(P.S.: no-one answer)

Jesse McNelis

unread,
Dec 12, 2012, 7:28:43 PM12/12/12
to Catalin Patulea, Andrew Gerrand, Brad Fitzpatrick, Michael Jones, golang-nuts
On Thu, Dec 13, 2012 at 11:25 AM, Catalin Patulea <cata...@google.com> wrote:
How was the epoch chosen? :)

Francesc Campoy Flores

unread,
Dec 12, 2012, 7:30:16 PM12/12/12
to Brad Fitzpatrick, Andrew Gerrand, golang-nuts
A (not very random) race: http://play.golang.org/p/y0tFGuIs9c


--
 
 



--
--
Francesc

Kevin Gillette

unread,
Dec 12, 2012, 10:14:53 PM12/12/12
to golan...@googlegroups.com
On Wednesday, December 12, 2012 4:47:07 PM UTC-7, Andrew Gerrand wrote:

 You know, Shatner charges royalties for that kind of stuff.

Kyle Lemons

unread,
Dec 12, 2012, 11:49:56 PM12/12/12
to Andrew Gerrand, Brad Fitzpatrick, Catalin Patulea, Michael Jones, golang-nuts
I would looooove to be able to turn something like that on for tests.

Also, major kudos for getting this done.  The playground was super shiny before, but it's taken on a life of its own now.  People might learn Go just to be able to run code that makes it do cool stuff ;-).


--
 
 

mattn

unread,
Dec 13, 2012, 1:15:08 AM12/13/12
to golan...@googlegroups.com

Andrew Gerrand

unread,
Dec 13, 2012, 3:09:36 AM12/13/12
to Gary Scarr, golang-nuts
On 13 December 2012 16:00, Gary Scarr <sca...@gmail.com> wrote:
Great stuff, but did the changes break Codewalk?  I'm seeing no code showing in Chrome on either Win 7 or OS X.

You're right. The codewalks are broken, probably as a side effect of the update. I will look into it.

Thanks,
Andrew

Jan Mercl

unread,
Dec 13, 2012, 6:38:23 AM12/13/12
to Brad Fitzpatrick, Andrew Gerrand, golang-nuts
On Thu, Dec 13, 2012 at 1:08 AM, Brad Fitzpatrick <brad...@golang.org> wrote:
> Balls: http://play.golang.org/p/rX_3WcpUOZ

Life: http://play.golang.org/p/6j5z_RNr0q

-j

Job van der Zwan

unread,
Dec 13, 2012, 7:38:23 AM12/13/12
to golan...@googlegroups.com, Brad Fitzpatrick, Andrew Gerrand
Beautiful!

roger peppe

unread,
Dec 13, 2012, 8:03:33 AM12/13/12
to Job van der Zwan, golang-nuts, Brad Fitzpatrick, Andrew Gerrand
of course, the nice thing about virtual time is you get
virtual-nanosecond accuracy:

http://play.golang.org/p/UpwhEcm_Vh
> --
>
>

Guilherme Lino

unread,
Dec 13, 2012, 2:34:29 PM12/13/12
to golan...@googlegroups.com
loool great go!

nguye...@hotmail.co.uk

unread,
Dec 21, 2017, 12:14:32 PM12/21/17
to golang-nuts
I cannot set a d for func Sleep().
Here is the code:
package main

import (
"fmt"
"time"
)

var c = make(chan int)

func main() {
go send(0, 3)
go send(1, 2)
go send(2, 1)
for i := 0; i < 3; i++ {
fmt.Printf("%v %v\n", <-c, time.Now())
}
}

func send(v int, d 3.Second) {
time.Sleep(d)
c <- v
}

Shawn Milochik

unread,
Dec 21, 2017, 12:18:02 PM12/21/17
to golang-nuts
d should be a time.Duration -- "3.Second" isn't a valid type.

If you're trying to set a default value, you can't. You can just check in the function whether it equals zero and set it to a default.
Reply all
Reply to author
Forward
0 new messages