当前位置: 首页 > news >正文

网站基础建设一般多少钱扬州seo博客

网站基础建设一般多少钱,扬州seo博客,大学科研项目做网站,单位门户网站建设方案设想一下你在接收源源不断的数据,如果有700ms没有收到,则认为是一个超时,需要做出处理。 逻辑上可以设计一个grouting,里面放一个通道,每收到一条数据进行相应处理。通道中夹杂一个timer定时器的处理,若通道在700ms内…

设想一下你在接收源源不断的数据,如果有700ms没有收到,则认为是一个超时,需要做出处理。

逻辑上可以设计一个grouting,里面放一个通道,每收到一条数据进行相应处理。通道中夹杂一个timer定时器的处理,若通道在700ms内有数据,则定时器被重置,重新等待700ms再调用定时器处理函数,否则,700ms时间到,运行定时器处理函数。示例代码如下:

​
package mainimport ("fmt""runtime/debug""strings""time"
)type demoSaveSuite struct {chanDemoSave chan string
}const dbSaveWaitDuration = 700 * time.Millisecondfunc (s *demoSaveSuite) DemoHandler() {go func() {defer func() {if r := recover(); r != nil {fmt.Println(string(debug.Stack()))}}()var timer *time.Timerfor sqlEntity := range s.chanDemoSave {fmt.Printf("Received SQL entity: %s\n", sqlEntity)// 检查 sqlEntity 是否包含 "SQL_Entity_5"if strings.Contains(sqlEntity, "SQL_Entity_5") {if timer != nil {timer.Stop()timer = nil // 将 timer 设为 nil 以确保不再使用它continue    // 跳过本次循环的后续部分}}if timer == nil {timer = time.AfterFunc(dbSaveWaitDuration, func() {fmt.Printf("Executing action after delay for entity: %s\n", sqlEntity)})} else {timer.Reset(dbSaveWaitDuration)}}}()
}func main() {// You can place your main code here if neededsuite := &demoSaveSuite{chanDemoSave: make(chan string, 5), // Buffer to avoid blocking when sending messages}go suite.DemoHandler()// Send the first SQL entitysuite.chanDemoSave <- "SQL_Entity_1_300Millisecond"time.Sleep(300 * time.Millisecond) // sleep a bit, but not enough for dbSaveWaitDuration// Send the second SQL entitysuite.chanDemoSave <- "SQL_Entity_2_800Millisecond"time.Sleep(800 * time.Millisecond) // let the timer expire for SQL_Entity_1// Send the third SQL entity to test resetting the timersuite.chanDemoSave <- "SQL_Entity_3_300Millisecond"time.Sleep(300 * time.Millisecond) // sleep a bit, but not enough for dbSaveWaitDuration// Send the fourth SQL entitysuite.chanDemoSave <- "SQL_Entity_4_800Millisecond"time.Sleep(800 * time.Millisecond) // let the timer expire for SQL_Entity_3// Send the fourth SQL entitysuite.chanDemoSave <- "SQL_Entity_5_2500Millisecond"time.Sleep(2500 * time.Millisecond) // let the timer expire for SQL_Entity_3// Close the channelclose(suite.chanDemoSave)
}​

代码动行结果:

Received SQL entity: SQL_Entity_1_300Millisecond
Received SQL entity: SQL_Entity_2_800Millisecond
Executing action after delay for entity: SQL_Entity_2_800Millisecond
Received SQL entity: SQL_Entity_3_900Millisecond
Received SQL entity: SQL_Entity_4_800Millisecond
Executing action after delay for entity: SQL_Entity_4_800Millisecond
Received SQL entity: SQL_Entity_5_2500Millisecond
Executing action after delay for entity: SQL_Entity_5_2500Millisecond

从运行结果看,只要超过700ms没有数据进入,就会引发定时器的回调,并且从2500ms的超时看只激发了一次,说明这里的定时器只会运行一次。没有超过700ms的,由于定时器被重置了,又开始等700ms才会运行,运行SQL_Entity_3时,定时器被删除,从结果看,虽然间隔是900ms远超700ms,依然定时器没有执行。接收到SQL_Entity_4时,由于timer已经为nil,因此又重新开启定时器

http://www.hkea.cn/news/89359/

相关文章:

  • 怎么在建设厅网站报名广州网站优化服务
  • 怎么用dw做静态网站b站好看的纪录片免费
  • 济南网站建设那家好网站制作公司有哪些
  • 域名和网站名不一样营销公司
  • discuz做电影网站免费网站seo
  • 惠民建设局网站明年2024年有疫情吗
  • 卫龙的网站是谁做的今日的新闻
  • 厚街找人做网站动态网站设计
  • 永春县住房和城乡规划建设局网站太原seo排名优化软件
  • 怎么上网站后台爱站小工具计算器
  • 网页编辑岗位职责seo上海优化
  • 网站做二维码吗做网站的外包公司
  • 郑州市中原区疫情最新消息上海网站营销seo方案
  • 狂人站群系统中国最权威的网站排名
  • 简单网站开发实例网站运营工作的基本内容
  • 飞机免费代理ip爱站网seo综合查询工具
  • 河南焦作有做网站开发的公司吗巩义网络推广公司
  • 邓州做网站网络广告有哪些形式
  • 爬闪数媒 网站建设网站建站流程
  • 网站建设广州白云百度统计app下载
  • 惠州短视频seoseowhy论坛
  • 肇庆网站快速排名优化温州seo排名公司
  • 北京疫情死亡人数最新消息王通seo赚钱培训
  • 北京做网站的外包公司营销策划方案案例范文
  • 专业做酒店网站关键词优化排名软件流量词
  • 做网站推广代理上海网络推广服务
  • wordpress可以做大吗搜索引擎优化的英语简称
  • 民治专业做网站公司中国企业500强排行榜
  • 潍坊 公司 网站seo点击排名器
  • 网站可以做赌博广告建站宝盒