第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 cron 運行 Go 方法

使用 cron 運行 Go 方法

Go
慕妹3242003 2021-09-20 10:48:16
我正在嘗試編寫一個程序,該程序?qū)⒃谔囟〞r間間隔內(nèi)連續(xù)調(diào)用一個方法。我正在使用 cron 庫來嘗試實現(xiàn)這一點,但是當(dāng)我運行該程序時,它只會執(zhí)行并完成而沒有任何輸出。下面是我正在嘗試做的一個基本示例。非常感謝您的幫助!package mainimport (    "fmt"    "github.com/robfig/cron")func main() {    c := cron.New()    c.AddFunc("1 * * * * *", RunEverySecond)    c.Start()}func RunEverySecond() {    fmt.Println("----")}
查看完整描述

3 回答

?
波斯汪

TA貢獻(xiàn)1811條經(jīng)驗 獲得超4個贊

為此使用外部包是矯枉過正的,該time包具有您需要的一切:


package main


import (

    "fmt"

    "time"

)


func main() {

    go func() {

        c := time.Tick(1 * time.Second)

        for range c {

            // Note this purposfully runs the function

            // in the same goroutine so we make sure there is

            // only ever one. If it might take a long time and

            // it's safe to have several running just add "go" here.

            RunEverySecond()

        }

    }()


    // Other processing or the rest of your program here.

    time.Sleep(5 * time.Second)


    // Or to block forever:

    //select {}

    // However, if doing that you could just stick the above for loop

    // right here without dropping it into a goroutine.

}


func RunEverySecond() {

    fmt.Println("----")

}


查看完整回答
反對 回復(fù) 2021-09-20
  • 3 回答
  • 0 關(guān)注
  • 247 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號