Best Rod code snippet using utils.Sleep
testblock_is_ready.go
Source:testblock_is_ready.go
...34 }35 if !d.CheckInstall(DaemonCh, AnswerDaemonCh, GoroutineName) {36 return37 }38 err = d.notMinerSetSleepTime(1800)39 if err != nil {40 log.Error("%v", err)41 return42 }43BEGIN:44 for {45 log.Info(GoroutineName)46 MonitorDaemonCh <- []string{GoroutineName, utils.Int64ToStr(utils.Time())}47 // пÑовеÑим, не нÑжно ли нам вÑйÑи из Ñикла48 if CheckDaemonsRestart(GoroutineName) {49 break BEGIN50 }51 LocalGateIp, err := d.GetMyLocalGateIp()52 if err != nil {53 if d.dPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }54 continue55 }56 if len(LocalGateIp) > 0 {57 if d.dPrintSleep(utils.ErrInfo(errors.New("len(LocalGateIp) > 0")), d.sleepTime) { break BEGIN }58 continue59 }60 // ÑколÑко нÑжно ÑпаÑÑ61 prevBlock, myUserId, myMinerId, currentUserId, level, levelsRange, err := d.TestBlock()62 if err != nil {63 if d.dPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }64 continue65 }66 log.Info("%v", prevBlock, myUserId, myMinerId, currentUserId, level, levelsRange)67 if myMinerId == 0 {68 if d.dPrintSleep(utils.ErrInfo(errors.New("myMinerId == 0 ")), d.sleepTime) { break BEGIN }69 continue70 }71 sleepData, err := d.GetSleepData()72 sleep := d.GetIsReadySleep(prevBlock.Level, sleepData["is_ready"])73 prevHeadHash := prevBlock.HeadHash74 // ÐÑли ÑлÑÑиÑÑÑ Ð¾ÑÐºÐ°Ñ Ð¸Ð»Ð¸ пÑÐ¸Ð´ÐµÑ Ð½Ð¾Ð²Ñй блок, Ñо testblock ÑÑÐ°Ð½ÐµÑ Ð½ÐµÐ°ÐºÑÑален75 startSleep := utils.Time()76 for i := 0; i < int(sleep); i++ {77 err, restart := d.dbLock()78 if restart {79 break BEGIN80 }81 if err != nil {82 if d.dPrintSleep(err, d.sleepTime) { break BEGIN }83 continue BEGIN84 }85 newHeadHash, err := d.Single("SELECT head_hash FROM info_block").String()86 if err != nil {87 if d.dPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }88 continue89 }90 d.dbUnlock()91 newHeadHash = string(utils.BinToHex([]byte(newHeadHash)))92 if newHeadHash != prevHeadHash {93 if d.dPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }94 continue BEGIN95 }96 log.Info("%v", "i", i, "time", utils.Time())97 if utils.Time()-startSleep > sleep {98 break99 }100 utils.Sleep(1) // Ñпим 1 Ñек. обÑее вÑÐµÐ¼Ñ = $sleep101 }102 /*103 Ðаголовок104 TYPE (0-блок, 1-ÑÑ-Ñ) FF (256)105 BLOCK_ID FF FF FF FF (4 294 967 295)106 TIME FF FF FF FF (4 294 967 295)107 USER_ID FF FF FF FF FF (1 099 511 627 775)108 LEVEL FF (256)109 SIGN Ð¾Ñ 128 байÑа до 512 байÑ. ÐодпиÑÑ Ð¾Ñ TYPE, BLOCK_ID, PREV_BLOCK_HASH, TIME, USER_ID, LEVEL, MRKL_ROOT110 Ðалее - Ñело блока (ТÑ-ии)111 */112 // блокиÑÑем Ð¸Ð·Ð¼ÐµÐ½ÐµÐ½Ð¸Ñ Ð´Ð°Ð½Ð½ÑÑ
в ÑеÑÑблоке113 // Ñакже, нÑжно блокиÑоваÑÑ main, Ñ.к. изменение в info_block и block_chain ведÑÑ Ðº Ð¸Ð·Ð¼ÐµÐ½ÐµÐ½Ð¸Ñ Ð¿Ð¾Ð´Ð¿Ð¸Ñи в testblock114 err, restart := d.dbLock()115 if restart {116 break BEGIN117 }118 if err != nil {119 if d.dPrintSleep(err, d.sleepTime) { break BEGIN }120 continue BEGIN121 }122 // за пÑомежÑÑок в main_unlock и main_lock мог пÑийÑи новÑй блок123 prevBlock, myUserId, myMinerId, currentUserId, level, levelsRange, err = d.TestBlock()124 if err != nil {125 if d.dPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }126 continue127 }128 log.Info("%v", prevBlock, myUserId, myMinerId, currentUserId, level, levelsRange)129 // на вÑÑкий ÑлÑÑай ÑбедимÑÑ, ÑÑо блок не изменилÑÑ130 if prevBlock.HeadHash != prevHeadHash {131 if d.unlockPrintSleep(utils.ErrInfo(errors.New("prevBlock.HeadHash != prevHeadHash")), d.sleepTime) { break BEGIN }132 continue133 }134 // ÑоÑÑавим блок. заголовок + Ñело + подпиÑÑ135 testBlockData, err := d.OneRow("SELECT * FROM testblock WHERE status = 'active'").String()136 if err != nil {137 if d.unlockPrintSleep(utils.ErrInfo(errors.New("prevBlock.HeadHash != prevHeadHash")), d.sleepTime) { break BEGIN }138 continue139 }140 log.Debug("testBlockData: %v", testBlockData)141 if len(testBlockData) == 0 {142 if d.unlockPrintSleep(utils.ErrInfo(errors.New("null $testblock_data")), d.sleepTime) { break BEGIN }143 continue144 }145 // полÑÑим ÑÑанзакÑии146 var testBlockDataTx []byte147 transactionsTestBlock, err := d.GetList("SELECT data FROM transactions_testblock ORDER BY id ASC").String()148 if err != nil {149 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }150 continue BEGIN151 }152 for _, data := range transactionsTestBlock {153 testBlockDataTx = append(testBlockDataTx, utils.EncodeLengthPlusData([]byte(data))...)154 }155 // в пÑомежÑÑке межде Ñем, как блок бÑл ÑгенеÑиÑован и запÑÑком данного ÑкÑипÑа Ð¼Ð¾Ð¶ÐµÑ Ð¸Ð·Ð¼ÐµÐ½Ð¸ÑÑÑÑ ÑекÑÑий блок156 // поÑÑÐ¾Ð¼Ñ Ð½Ñжно пÑовеÑÑÑÑ Ð¿Ð¾Ð´Ð¿Ð¸ÑÑ Ð±Ð»Ð¾ÐºÐ° из ÑеÑÑблока157 prevBlockHash, err := d.Single("SELECT hash FROM info_block").Bytes()158 if err != nil {159 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }160 continue BEGIN161 }162 prevBlockHash = utils.BinToHex(prevBlockHash)163 nodePublicKey, err := d.GetNodePublicKey(utils.StrToInt64(testBlockData["user_id"]))164 if err != nil {165 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }166 continue BEGIN167 }168 forSign := fmt.Sprintf("0,%v,%s,%v,%v,%v,%s", testBlockData["block_id"], prevBlockHash, testBlockData["time"], testBlockData["user_id"], testBlockData["level"], utils.BinToHex([]byte(testBlockData["mrkl_root"])))169 log.Debug("forSign %v", forSign)170 log.Debug("signature %x", testBlockData["signature"])171 p := new(dcparser.Parser)172 p.DCDB = d.DCDB173 // пÑовеÑÑем подпиÑÑ174 _, err = utils.CheckSign([][]byte{nodePublicKey}, forSign, []byte(testBlockData["signature"]), true)175 if err != nil {176 log.Error("incorrect signature %v")177 p.RollbackTransactionsTestblock(true)178 err = d.ExecSql("DELETE FROM testblock")179 if err != nil {180 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }181 continue BEGIN182 }183 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }184 continue BEGIN185 }186 // ÐÐÐ187 if utils.StrToInt64(testBlockData["block_id"]) == prevBlock.BlockId {188 log.Error("testBlockData block_id = prevBlock.BlockId (%v=%v)", testBlockData["block_id"], prevBlock.BlockId)189 err = p.RollbackTransactionsTestblock(true)190 if err != nil {191 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }192 continue BEGIN193 }194 err = d.ExecSql("DELETE FROM testblock")195 if err != nil {196 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }197 continue BEGIN198 }199 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }200 continue BEGIN201 }202 // гоÑовим заголовок203 newBlockIdBinary := utils.DecToBin(utils.StrToInt64(testBlockData["block_id"]), 4)204 timeBinary := utils.DecToBin(utils.StrToInt64(testBlockData["time"]), 4)205 userIdBinary := utils.DecToBin(utils.StrToInt64(testBlockData["user_id"]), 5)206 levelBinary := utils.DecToBin(utils.StrToInt64(testBlockData["level"]), 1)207 //prevBlockHashBinary := prevBlock.Hash208 //merkleRootBinary := testBlockData["mrklRoot"];209 // заголовок210 blockHeader := utils.DecToBin(0, 1)211 blockHeader = append(blockHeader, newBlockIdBinary...)212 blockHeader = append(blockHeader, timeBinary...)213 blockHeader = append(blockHeader, userIdBinary...)214 blockHeader = append(blockHeader, levelBinary...)215 blockHeader = append(blockHeader, utils.EncodeLengthPlusData([]byte(testBlockData["signature"]))...)216 // Ñам блок217 block := append(blockHeader, testBlockDataTx...)218 log.Debug("block %x", block)219 // ÑепеÑÑ Ð½Ñжно ÑазнеÑÑи блок по ÑаблиÑам и поÑле ÑÑого Ð¼Ñ Ð±Ñдем его ÑлаÑÑ Ð²Ñем нодам ÑкÑипÑом disseminator.php220 p.BinaryData = block221 err = p.ParseDataFront()222 if err != nil {223 if d.dPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }224 continue BEGIN225 }226 // и можно ÑдалÑÑÑ Ð´Ð°Ð½Ð½Ñе о ÑеÑÑблоке, Ñ.к. они пеÑеÑел в ноÑмалÑнÑй блок227 err = d.ExecSql("DELETE FROM transactions_testblock")228 if err != nil {229 if d.dPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }230 continue BEGIN231 }232 err = d.ExecSql("DELETE FROM testblock")233 if err != nil {234 if d.dPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }235 continue BEGIN236 }237 // Ð¼ÐµÐ¶Ð´Ñ testblock_generator и testbock_is_ready238 p.RollbackTransactionsTestblock(false)239 d.dbUnlock()240 if d.dSleep(d.sleepTime) {241 break BEGIN242 }243 }244 log.Debug("break BEGIN %v", GoroutineName)245}...
clear.go
Source:clear.go
...43 if restart {44 break BEGIN45 }46 if err != nil {47 if d.dPrintSleep(err, d.sleepTime) { break BEGIN }48 continue BEGIN49 }50 blockId, err := d.GetBlockId()51 if err != nil {52 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }53 continue BEGIN54 }55 if blockId == 0 {56 if d.unlockPrintSleep(utils.ErrInfo("blockId == 0"), d.sleepTime) { break BEGIN }57 continue BEGIN58 }59 log.Debug("blockId: %d", blockId)60 variables, err := d.GetAllVariables()61 if err != nil {62 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }63 continue BEGIN64 }65 // ÑиÑÑим log_transactions каждÑе 15 минÑÑ. УдалÑем даннÑе, коÑоÑÑе ÑÑаÑÑе 36 ÑаÑов.66 // Ðожно ÑдалÑÑÑ Ð¸ Ñе, ÑÑо ÑÑаÑÑе rollback_blocks_2 + погÑеÑноÑÑÑ Ð´Ð»Ñ Ð²Ñемени ÑÑанзакÑии (5-15 мин),67 // но пÑÑÑÑ Ð±ÑÐ´ÐµÑ 36 Ñ. - Ñ Ñ
оÑоÑим запаÑом.68 err = d.ExecSql("DELETE FROM log_transactions WHERE time < ?", utils.Time()-86400*3)69 if err != nil {70 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }71 continue BEGIN72 }73 // ÑеÑез rollback_blocks_2 Ñ Ð·Ð°Ð¿Ð°Ñом 14400 блоков ÑиÑÑим ÑÐ°Ð±Ð»Ñ log_votes где еÑÑÑ del_block_id74 // пÑи ÑÑом, еÑли пÑовеÑÑÑÑиÑ
бÑÐ´ÐµÑ Ð¼Ð°Ð»Ð¾, Ñо Ñабла Ð¼Ð¾Ð¶ÐµÑ Ð·Ð°Ñ
ламиÑÑÑÑ Ð½ÐµÐ·Ð°ÐºÐ¾Ð½ÑеннÑми голоÑованиÑми75 err = d.ExecSql("DELETE FROM log_votes WHERE del_block_id < ? AND del_block_id > 0", blockId-variables.Int64["rollback_blocks_2"]-14400)76 if err != nil {77 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }78 continue BEGIN79 }80 // ÑеÑез 14400 блоков ÑиÑÑим ÑÐ°Ð±Ð»Ñ wallets_buffer где еÑÑÑ del_block_id81 err = d.ExecSql("DELETE FROM wallets_buffer WHERE del_block_id < ? AND del_block_id > 0", blockId-variables.Int64["rollback_blocks_2"]-14400)82 if err != nil {83 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }84 continue BEGIN85 }86 // ÑиÑÑим вÑе _log_time_87 err = d.ExecSql("DELETE FROM log_time_votes_complex WHERE time < ?", utils.Time()-variables.Int64["limit_votes_complex_period"]-86400)88 if err != nil {89 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }90 continue BEGIN91 }92 err = d.ExecSql("DELETE FROM log_time_commission WHERE time < ?", utils.Time()-variables.Int64["limit_commission_period"]-86400)93 if err != nil {94 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }95 continue BEGIN96 }97 err = d.ExecSql("DELETE FROM log_time_change_host WHERE time < ?", utils.Time()-variables.Int64["limit_change_host_period"]-86400)98 if err != nil {99 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }100 continue BEGIN101 }102 err = d.ExecSql("DELETE FROM log_time_votes_miners WHERE time < ?", utils.Time()-variables.Int64["limit_votes_miners_period"]-86400)103 if err != nil {104 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }105 continue BEGIN106 }107 err = d.ExecSql("DELETE FROM log_time_primary_key WHERE time < ?", utils.Time()-variables.Int64["limit_primary_key_period"]-86400)108 if err != nil {109 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }110 continue BEGIN111 }112 err = d.ExecSql("DELETE FROM log_time_node_key WHERE time < ?", utils.Time()-variables.Int64["limit_node_key_period"]-86400)113 if err != nil {114 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }115 continue BEGIN116 }117 err = d.ExecSql("DELETE FROM log_time_mining WHERE time < ?", utils.Time()-variables.Int64["limit_mining_period"]-86400)118 if err != nil {119 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }120 continue BEGIN121 }122 err = d.ExecSql("DELETE FROM log_time_message_to_admin WHERE time < ?", utils.Time()-variables.Int64["limit_message_to_admin_period"]-86400)123 if err != nil {124 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }125 continue BEGIN126 }127 err = d.ExecSql("DELETE FROM log_time_holidays WHERE time < ?", utils.Time()-variables.Int64["limit_holidays_period"]-86400)128 if err != nil {129 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }130 continue BEGIN131 }132 err = d.ExecSql("DELETE FROM log_time_change_geolocation WHERE time < ?", utils.Time()-variables.Int64["limit_change_geolocation_period"]-86400)133 if err != nil {134 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }135 continue BEGIN136 }137 err = d.ExecSql("DELETE FROM log_time_cash_requests WHERE time < ?", utils.Time()-variables.Int64["limit_cash_requests_out_period"]-86400)138 if err != nil {139 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }140 continue BEGIN141 }142 err = d.ExecSql("DELETE FROM log_time_promised_amount WHERE time < ?", utils.Time()-variables.Int64["limit_promised_amount_period"]-86400)143 if err != nil {144 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }145 continue BEGIN146 }147 err = d.ExecSql("DELETE FROM log_time_abuses WHERE time < ?", utils.Time()-variables.Int64["limit_abuses_period"]-86400)148 if err != nil {149 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }150 continue BEGIN151 }152 err = d.ExecSql("DELETE FROM log_time_new_miner WHERE time < ?", utils.Time()-variables.Int64["limit_new_miner_period"]-86400)153 if err != nil {154 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }155 continue BEGIN156 }157 err = d.ExecSql("DELETE FROM log_time_votes WHERE time < ?", utils.Time()-86400-86400)158 if err != nil {159 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }160 continue BEGIN161 }162 err = d.ExecSql("DELETE FROM log_time_votes_nodes WHERE time < ?", utils.Time()-variables.Int64["node_voting_period"]-86400)163 if err != nil {164 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }165 continue BEGIN166 }167 err = d.ExecSql("DELETE FROM log_wallets WHERE block_id < ? AND block_id > 0", blockId-variables.Int64["rollback_blocks_2"]-14400)168 if err != nil {169 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }170 continue BEGIN171 }172 err = d.ExecSql("DELETE FROM log_time_money_orders WHERE del_block_id < ? AND del_block_id > 0", blockId-variables.Int64["rollback_blocks_2"]-14400)173 if err != nil {174 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }175 continue BEGIN176 }177 arr := []string{"log_commission",178 "log_faces",179 "log_forex_orders",180 "log_forex_orders_main",181 "log_miners",182 "log_miners_data",183 "log_points",184 "log_promised_amount",185 "log_recycle_bin",186 "log_spots_compatibility",187 "log_users",188 "log_votes_max_other_currencies",189 "log_votes_max_promised_amount",190 "log_votes_miner_pct",191 "log_votes_reduction",192 "log_votes_user_pct",193 "log_wallets"}194 for _, table := range arr {195 err = d.ExecSql("DELETE FROM "+table+" WHERE block_id < ? AND block_id > 0", blockId-variables.Int64["rollback_blocks_2"]-14400)196 if err != nil {197 if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) { break BEGIN }198 continue BEGIN199 }200 }201 log.Debug("variables.Int64[rollback_blocks_2]: %v", variables.Int64["rollback_blocks_2"])202 d.dbUnlock()203 if d.dSleep(d.sleepTime) {204 break BEGIN205 }206 }207 log.Debug("break BEGIN %v", GoroutineName)208}...
generator.go
Source:generator.go
...21 }22}23func (g *Generator) Start() {24 go func() {25 time.Sleep(10)26 for {27 time.Sleep(time.Second * 45)28 pedestrian := actors.NewPedestrian(29 utils.PedestrianWestToEastNorth,30 g.register,31 g.semaphores[utils.PedestrianNorthLeft].OutputChan,32 g.draw,33 g.crossingChan,34 utils.PedestrianNorthDraw,35 )36 pedestrian.StartPedestrian()37 }38 }()39 go func() {40 time.Sleep(time.Second * 6)41 for {42 time.Sleep(time.Second * 50)43 pedestrian := actors.NewPedestrian(44 utils.PedestrianEastToWestNorth,45 g.register,46 g.semaphores[utils.PedestrianNorthRight].OutputChan,47 g.draw,48 g.crossingChan,49 utils.PedestrianNorthDraw,50 )51 pedestrian.StartPedestrian()52 }53 }()54 go func() {55 time.Sleep(time.Second * 35)56 for {57 time.Sleep(time.Second * 62)58 pedestrian := actors.NewPedestrian(59 utils.PedestrianWestToEastSouth,60 g.register,61 g.semaphores[utils.PedestrianSouthLeft].OutputChan,62 g.draw,63 g.crossingChan,64 utils.PedestrianSouthDraw,65 )66 pedestrian.StartPedestrian()67 }68 }()69 go func() {70 time.Sleep(time.Second * 70)71 for {72 time.Sleep(time.Second * 71)73 pedestrian := actors.NewPedestrian(74 utils.PedestrianEastToWestSouth,75 g.register,76 g.semaphores[utils.PedestrianSouthRight].OutputChan,77 g.draw,78 g.crossingChan,79 utils.PedestrianSouthDraw,80 )81 pedestrian.StartPedestrian()82 }83 }()84 go func() {85 for {86 time.Sleep(time.Second * 60)87 pedestrian := actors.NewPedestrian(88 utils.PedestrianNorthToSouthEast,89 g.register,90 g.semaphores[utils.PedestrianEastNorth].OutputChan,91 g.draw,92 g.crossingChan,93 utils.PedestrianEastDraw,94 )95 pedestrian.StartPedestrian()96 }97 }()98 go func() {99 time.Sleep(time.Second * 25)100 for {101 time.Sleep(time.Second * 65)102 pedestrian := actors.NewPedestrian(103 utils.PedestrianNorthToSouthWest,104 g.register,105 g.semaphores[utils.PedestrianWestNorth].OutputChan,106 g.draw,107 g.crossingChan,108 utils.PedestrianWestDraw,109 )110 pedestrian.StartPedestrian()111 }112 }()113 go func() {114 for {115 time.Sleep(time.Second * 55)116 pedestrian := actors.NewPedestrian(117 utils.PedestrianSouthToNorthEast,118 g.register,119 g.semaphores[utils.PedestrianEastSouth].OutputChan,120 g.draw,121 g.crossingChan,122 utils.PedestrianEastDraw,123 )124 pedestrian.StartPedestrian()125 }126 }()127 go func() {128 time.Sleep(time.Second * 55)129 for {130 time.Sleep(time.Second * 51)131 pedestrian := actors.NewPedestrian(132 utils.PedestrianSouthToNorthWest,133 g.register,134 g.semaphores[utils.PedestrianWestSouth].OutputChan,135 g.draw,136 g.crossingChan,137 utils.PedestrianWestDraw,138 )139 pedestrian.StartPedestrian()140 }141 }()142 go func() {143 time.Sleep(time.Second * 15)144 for {145 time.Sleep(time.Second * 80)146 car := actors.NewCar(147 utils.StraightVerticalToNorth,148 g.register,149 g.semaphores[utils.StraightVerticalToNorth].OutputChan,150 g.draw,151 g.crossingChan,152 )153 car.StartCar()154 }155 }()156 go func() {157 time.Sleep(time.Second * 10)158 for {159 time.Sleep(time.Second * 90)160 car := actors.NewCar(161 utils.StraightVerticalToSouth,162 g.register,163 g.semaphores[utils.StraightVerticalToSouth].OutputChan,164 g.draw,165 g.crossingChan,166 )167 car.StartCar()168 }169 }()170 go func() {171 time.Sleep(time.Second * 5)172 for {173 time.Sleep(time.Second * 70)174 car := actors.NewCar(175 utils.StraightHorizontalToWest,176 g.register,177 g.semaphores[utils.StraightHorizontalToWest].OutputChan,178 g.draw,179 g.crossingChan,180 )181 car.StartCar()182 }183 }()184 go func() {185 time.Sleep(time.Second * 10)186 for {187 time.Sleep(time.Second * 70)188 car := actors.NewCar(189 utils.StraightHorizontalToEast,190 g.register,191 g.semaphores[utils.StraightHorizontalToEast].OutputChan,192 g.draw,193 g.crossingChan,194 )195 car.StartCar()196 }197 }()198}...
Sleep
Using AI Code Generation
1import (2func main() {3 fmt.Println("Sleeping for 5 seconds")4 utils.Sleep(5)5 fmt.Println("Woke up")6}7import (8func Sleep(seconds int) {9 time.Sleep(time.Duration(seconds) * time.Second)10}11import (12func main() {13 bytes, err := ioutil.ReadFile("1.go")14 if err != nil {15 fmt.Println(err.Error())16 os.Exit(1)17 }18 fmt.Println(string(bytes))19}20import (21func main() {22 err := ioutil.WriteFile("1.go", []byte("package main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"Hello World\")\n}\n"), 0644)23 if err != nil {24 fmt.Println(err.Error())25 os.Exit(1)26 }27}28import (29func main() {30 err := os.Mkdir("utils", 0755)31 if err != nil {32 fmt.Println(err.Error())33 os.Exit(1)34 }35}36import (37func main() {38 err := os.RemoveAll("utils")39 if err != nil {40 fmt.Println(err.Error())41 os.Exit(1)42 }43}44import (45func main() {46 file, err := os.Create("1.go")47 if err != nil {48 fmt.Println(err.Error())49 os.Exit(1)50 }51 file.WriteString("package main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"Hello World\")\n}\n")52 file.Close()53}54import (55func main() {56 err := os.Remove("1.go")57 if err != nil {58 fmt.Println(err.Error())59 os.Exit(1)60 }61}
Sleep
Using AI Code Generation
1import "utils"2func main() {3 utils.Sleep(3)4}5import "time"6func Sleep(seconds int) {7 time.Sleep(time.Second * time.Duration(seconds))8}
Sleep
Using AI Code Generation
1import (2func main() {3 fmt.Println(stringutil.Reverse("!oG ,olleH"))4 fmt.Println(stringutil.MyName)5}6func Reverse(s string) string7func Title(s string) string8func Reverse(s string) string9func Title(s string) string10func Reverse(s string) string11func Title(s string) string12func Errorf(format string, a ...interface{}) error13func Fprint(w io.Writer, a ...interface{}) (n int, err error)14func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error)15func Fprintln(w io.Writer, a ...interface{}) (n int, err error)16func Fscan(r io.Reader, a ...interface{}) (n int, err error)17func Fscanf(r io.Reader, format string, a ...interface{}) (n int, err error)18func Fscanln(r io.Reader, a ...interface{}) (n int, err error)19func Print(a ...interface{}) (
Sleep
Using AI Code Generation
1import (2func main() {3 utils.Sleep(2 * time.Second)4 fmt.Println("Hello")5}6import (7func main() {8 utils.Sleep(2 * time.Second)9 fmt.Println("Hello")10}11import (12func main() {13 utils.Sleep(2 * time.Second)14 fmt.Println("Hello")15}16import (17func main() {18 utils.Sleep(2 * time.Second)19 fmt.Println("Hello")20}21import (22func main() {23 utils.Sleep(2 * time.Second)24 fmt.Println("Hello")25}26import (27func main() {28 utils.Sleep(2 * time.Second)29 fmt.Println("Hello")30}31import (32func main() {33 utils.Sleep(2 * time.Second)34 fmt.Println("Hello")35}36import (37func main() {38 utils.Sleep(2 * time.Second)39 fmt.Println("Hello")40}41import (42func main() {43 utils.Sleep(2 * time.Second)44 fmt.Println("Hello")45}
Sleep
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello World")4 utils.Sleep(2 * time.Second)5 fmt.Println("Hello World")6}7import (8func Sleep(t time.Duration) {9 time.Sleep(t)10}11import (12func TestSleep(t *testing.T) {13 start := time.Now()14 Sleep(2 * time.Second)15 end := time.Now()16 elapsed := end.Sub(start)17 if elapsed < 2*time.Second {18 t.Errorf("Sleep(2) took %v, expected at least 2s", elapsed)19 }20}21--- PASS: TestSleep (2.00s)22import (23func main() {24 fmt.Println("Hello World")25 utils.Sleep(2 * time.Second)26 fmt.Println("Hello World")27}28import (29func Sleep(t time.Duration) {30 time.Sleep(t)31}32import (33func TestSleep(t *testing.T) {34 start := time.Now()35 Sleep(2 * time.Second)36 end := time.Now()37 elapsed := end.Sub(start)38 if elapsed < 2*time.Second {39 t.Errorf("Sleep(2) took %v, expected at least 2s", elapsed)40 }41}42--- PASS: TestSleep (2.00s)43import (44func main() {45 fmt.Println("Hello World")46 utils.Sleep(2 * time.Second)47 fmt.Println("Hello World")48}49import (50func Sleep(t time.Duration) {51 time.Sleep(t)52}53import (
Sleep
Using AI Code Generation
1import "fmt"2import "time"3import "utils"4func main() {5fmt.Println("Hello")6utils.Sleep(time.Second * 2)7fmt.Println("World")8}9import "time"10func Sleep(d time.Duration) {11time.Sleep(d)12}13import "testing"14import "time"15func TestSleep(t *testing.T) {16start := time.Now()17Sleep(time.Second * 2)18elapsed := time.Since(start)19if elapsed < time.Second * 2 {20t.Errorf("Sleep took %v, expected %v", elapsed, time.Second * 2)21}22}23| `func Benchmark(b *testing.B)` | Benchmark runs the benchmark b. |24| `func BenchmarkXxx(*testing.B)` | BenchmarkXxx is a benchmark function. |25| `func Example()` | Example runs the example function. |26| `func ExampleXxx()` | ExampleXxx is an example function. |27| `func Fail()` | Fail marks the function as having failed but continues execution. |28| `func FailNow()` | FailNow marks the function as having failed and stops its execution. |29| `func Fatal(args ...interface{})` | Fatal is equivalent to Log followed by FailNow. |30| `func Fatalf(format string, args ...interface{})` | Fatalf is equivalent to Logf followed by FailNow. |31| `func Fatalln(args ...interface{})` | Fatalln is equivalent to Logln followed by FailNow. |32| `func Log(args ...interface{})` | Log formats its arguments using default formatting, analogous to Println, and records the text in the error log. |33| `func Logf(format string, args ...interface{})` | Logf formats its arguments according to the format, analogous to Printf, and records the text in the error log. |34| `func Logln(args ...interface{})` | Logln formats its arguments using default formatting, analogous to Println, and records the text in the error log. |35| `func Run(name string, f func(t *testing.T)) bool` | Run runs f as a subtest of t
Sleep
Using AI Code Generation
1import (2func main() {3 fmt.Println("Starting main")4 utils.Sleep(1000)5 fmt.Println("main ended")6}7import (8func main() {9 fmt.Println("Starting main")10 utils.Sleep(1000)11 fmt.Println("main ended")12}13import (14func main() {15 fmt.Println("Starting main")16 utils.Sleep(1000)17 fmt.Println("main ended")18}19import (20func main() {21 fmt.Println("Starting main")22 utils.Sleep(1000)23 fmt.Println("main ended")24}25import (26func main() {27 fmt.Println("Starting main")28 utils.Sleep(1000)29 fmt.Println("main ended")30}31import (32func main() {33 fmt.Println("Starting main")34 utils.Sleep(1000)35 fmt.Println("main ended")36}37import (38func main() {39 fmt.Println("Starting main")40 utils.Sleep(1000)41 fmt.Println("main ended")42}43import (44func main() {45 fmt.Println("Starting main")46 utils.Sleep(1000)47 fmt.Println("main ended")48}49import (50func main() {51 fmt.Println("Starting main")52 utils.Sleep(1000)53 fmt.Println("main ended")54}55import (56func main() {57 fmt.Println("Starting main")58 utils.Sleep(1000)
Sleep
Using AI Code Generation
1import (2func main() {3 fmt.Println("Sleeping for 5 seconds")4 utils.Sleep(time.Second * 5)5 fmt.Println("Done Sleeping")6}7import "time"8func Sleep(duration time.Duration) {9 time.Sleep(duration)10}11import (12func main() {13 fmt.Println("Sleeping for 5 seconds")14 utils.Sleep(time.Second * 5)15 fmt.Println("Done Sleeping")16}17import "time"18func Sleep(duration time.Duration) {19 time.Sleep(duration)20}21import (22func main() {23 fmt.Println("Sleeping for 5 seconds")24 utils.Sleep(time.Second * 5)25 fmt.Println("Done Sleeping")26}27import "time"28func Sleep(duration time.Duration) {29 time.Sleep(duration)30}31import (32func main() {33 fmt.Println("Sleeping for 5 seconds")34 utils.Sleep(time.Second * 5)35 fmt.Println("Done Sleeping")36}37import "time"38func Sleep(duration time.Duration) {39 time.Sleep(duration)40}41import (
Sleep
Using AI Code Generation
1import (2func main() {3 fmt.Println("hello world")4 utils.Sleep(2)5}6import (7func main() {8 fmt.Println("hello world")9 utils.Sleep(3)10}11import (12func main() {13 fmt.Println("hello world")14 utils.Sleep(4)15}16import (17func main() {18 fmt.Println("hello world")19 utils.Sleep(5)20}21import (22func main() {23 fmt.Println("hello world")24 utils.Sleep(6)25}26import (27func main() {28 fmt.Println("hello world")29 utils.Sleep(7)30}31import (32func main() {33 fmt.Println("hello world")34 utils.Sleep(8)35}36import (37func main() {38 fmt.Println("hello world")39 utils.Sleep(9)40}41import (42func main() {43 fmt.Println("hello world")44 utils.Sleep(10)45}46import (
Sleep
Using AI Code Generation
1import (2func main() {3 fmt.Println("main: will sleep for 5 seconds")4 golutils.Sleep(5)5 fmt.Println("main: woke up after 5 seconds")6}7import (8func main() {9 fmt.Println("main: will log a message")10 golutils.Log("main: this is a log message")11}12import (13func main() {14 fmt.Println("main: will get an env variable")15 golutils.GetEnv("GOPATH")16}17import (18func main() {19 fmt.Println("main: will sleep for 5 seconds")20 golutils.Sleep(5)21 fmt.Println("main: woke up after 5 seconds")22 fmt.Println("main: will log a message")23 golutils.Log("main: this is a log message")24 fmt.Println("main: will get an env variable")25 golutils.GetEnv("GOPATH")26}27import (28func main() {29 fmt.Println("main: will generate a random number")30 golrand.RandInt(0, 100)31}32import (33func main() {34 fmt.Println("main: will generate a random string")35 golstring.RandString(10)36}37import (38func main() {39 fmt.Println("main: will generate a hash")40 golhash.Hash("hello
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!