Go time Ticker Set timer, more strange ...

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

On the example

Package Mainimport (    //    "bytes"    //    "Encoding/json"    "FMT"    //    "OS"/    /    "Gopkg.in/mgo.v2"    //    "Gopkg.in/mgo.v2/bson"    //    "Io/ioutil"    //    "Net/http"    //    "strings"    //    "Net/url"    "Time") func main () {    Ticker:= time. Newticker (Ten * time . Second) for    i:= 0; I < 10; i++ {Time        := <-Ticker. C        FMT. Println (time. String ())    }}

Execution results

Wifimac:webdemo cdpmac$ Go Run src/server/timetest.go

2015-08-24 16:22:23.590564088 +0800 CST

2015-08-24 16:22:33.591194618 +0800 CST

2015-08-24 16:22:43.587720967 +0800 CST

2015-08-24 16:22:53.590231413 +0800 CST

2015-08-24 16:23:03.591164202 +0800 CST

....

You don't have to look down.

I really hate it. Go compile run-time dependency check! There are introduced, but not applied packages that have been created, but not used by the variable, not allowed.

Another special case was found.

Output time, completely out of common sense,

Fmt. Println in theory is output by line, in this case
Actually, it turns out that

2015-08-24 16:22:23.590564088 +0800 cst2015-08-24 16:22:33.591194618 +0800 cst2015-08-24 16:22:43.587720967 +0800 cst2015-08-24 16:22:53.590231413 +0800 cst2015-08-24 16:23:03.591164202 +0800 cst2015-08-24 16:23:13.588811769 +0800 cst2015-08-24 16:23:23.587282627 +0800 cst2015-08-24 16:23:33.588753016 +0800 cst2015-08-24 16:23:43.591157197 +0800 cst2015-08-24 16:23:53.589934072 +0800 CST

It's supposed to be a shell problem.

Continue theme

No ready-made data found.

See the sample test code for the official package

See the time part of Go source code ticker structure

<-chan Time//The channel on which the ticks is DELIVERED.R Runtimetimer}

Time is similar

There is a read-only Chanel "object"


Time and ticket calls to go

or Timmer internal and other language development ideas are completely different.

Other languages, many are registered callback functions, timing, time to call callback.

Go is through Chan

of blocking implementations.

Call the place and read Chan

Timed, time to, write value to Chan, block out, call function.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.