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

做网站切图响应式企业网站源码

做网站切图,响应式企业网站源码,苏州整站优化,腾讯广告联盟作用#xff1a;用于在go协程中 传递上下文、超时、取消、传值 底层实现#xff1a;是由互斥锁、channel、map来实现的 互斥锁#xff1a;保护临界资源 channel: 用于信号通知#xff0c;比如ctx.Done() map: 保存父ctx下派生的所有子ctx, 父ctx关闭#xff0c;子ctx都关…作用用于在go协程中 传递上下文、超时、取消、传值 底层实现是由互斥锁、channel、map来实现的 互斥锁保护临界资源 channel: 用于信号通知比如ctx.Done() map: 保存父ctx下派生的所有子ctx, 父ctx关闭子ctx都关闭 实现的接口 type Context interface {Deadline() (deadline time.Time, ok bool)Done() -chan struct{}Err() errorValue(key interface{}) interface{} }空ctx type emptyCtx intfunc (*emptyCtx) Deadline() (deadline time.Time, ok bool) {return }func (*emptyCtx) Done() -chan struct{} {return nil }func (*emptyCtx) Err() error {return nil }func (*emptyCtx) Value(key interface{}) interface{} {return nil }cancel ctx 使用map保存所有子ctx确保父ctx cancel后子ctx也cancel type cancelCtx struct {Contextmu sync.Mutex // protects following fieldsdone chan struct{} // created lazily, closed by first cancel callchildren map[canceler]struct{} // set to nil by the first cancel callerr error // set to non-nil by the first cancel call }func WithCancel(parent Context) (ctx Context, cancel CancelFunc) {if parent nil {panic(cannot create context from nil parent)}c : newCancelCtx(parent)propagateCancel(parent, c)return c, func() { c.cancel(true, Canceled) } }// newCancelCtx returns an initialized cancelCtx. func newCancelCtx(parent Context) cancelCtx {return cancelCtx{Context: parent} }func propagateCancel(parent Context, child canceler) {fmt.Println(propagateCancel)done : parent.Done()if done nil {return // parent is never canceled}select {case -done:// parent is already canceledchild.cancel(false, parent.Err())returndefault:}if p, ok : parentCancelCtx(parent); ok {p.mu.Lock()if p.err ! nil {// parent has already been canceledchild.cancel(false, p.err)} else {if p.children nil {p.children make(map[canceler]struct{})}// 保存子ctxp.children[child] struct{}{}}p.mu.Unlock()} else {atomic.AddInt32(goroutines, 1)go func() {select {case -parent.Done():child.cancel(false, parent.Err())case -child.Done():}}()} }func (c *cancelCtx) cancel(removeFromParent bool, err error) {if err nil {panic(context: internal error: missing cancel error)}c.mu.Lock()if c.err ! nil {c.mu.Unlock()return // already canceled}c.err errif c.done nil {c.done closedchan} else {close(c.done) // 关闭channel, 用于通知ctx.Done()}// 关闭所有子ctxfor child : range c.children {// NOTE: acquiring the childs lock while holding parents lock.child.cancel(false, err)}c.children nilc.mu.Unlock()if removeFromParent {removeChild(c.Context, c)} } timeout ctx 在cancelctx的基础上实现只是多了个定时器自动调用cancel type timerCtx struct {cancelCtxtimer *time.Timer // Under cancelCtx.mu.deadline time.Time }func WithDeadline(parent Context, d time.Time) (Context, CancelFunc) {if parent nil {panic(cannot create context from nil parent)}if cur, ok : parent.Deadline(); ok cur.Before(d) {// The current deadline is already sooner than the new one.return WithCancel(parent)}c : timerCtx{cancelCtx: newCancelCtx(parent),deadline: d,}propagateCancel(parent, c)dur : time.Until(d)if dur 0 {c.cancel(true, DeadlineExceeded) // deadline has already passedreturn c, func() { c.cancel(false, Canceled) }}c.mu.Lock()defer c.mu.Unlock()if c.err nil {c.timer time.AfterFunc(dur, func() {c.cancel(true, DeadlineExceeded)})}return c, func() { c.cancel(true, Canceled) } }value ctx type valueCtx struct {Contextkey, val interface{} } func WithValue(parent Context, key, val interface{}) Context {if parent nil {panic(cannot create context from nil parent)}if key nil {panic(nil key)}// if !reflectlite.TypeOf(key).Comparable() {// panic(key is not comparable)//}return valueCtx{parent, key, val} } func (c *valueCtx) Value(key interface{}) interface{} {if c.key key {return c.val}return c.Context.Value(key) }
http://www.hkea.cn/news/14287491/

相关文章:

  • 网站招标书怎么做哪个网站做期货数字币
  • 淄博建设网站家乡网站设计模板
  • 广州达美网站建设iis wordpress固定链接404
  • 免费gif动图在线制作网站wordpress 项目选项
  • 网站开发招标采购需求太原网络推广
  • 怎么进网站源码的后台市北网站建设
  • 网站建设具备哪些技术人员商务网站建设实训心得
  • 怎么做家具网站网站建设制作人员招聘要求
  • 可以做兼职的网站有哪些工作室wordpress 百度经验主题
  • app与网站的关系中企动力股票代码
  • 做淘宝客网站要注意什么汽车网站设计论文
  • 广西网站建设推广报价游戏网站开发设计报告
  • 龙南县建设局网站上海12333公共招聘网
  • 此网站不支持下载视频怎么办万维定制平台
  • 阿克苏市建设局网站做网站找八埏
  • 优酷视频接到网站怎么做中关村手机之家报价
  • 锦州企业网站建设石家庄建站工具
  • 珠海免费网站建设企业文化展示墙设计
  • 厦门做网站seo做漫画网站
  • 网站如何制作做吸引客户君通网站怎么样
  • 西安凤城二路网站建设单位申请免费网站
  • 外贸网站推广招聘上海app服务商
  • 河北建设厅注册中心网站微采服企腾网
  • 美丽乡村建设发展论坛网站免费创建个人网站
  • cms建站系统哪个好手机型号最全的网站
  • 广州住房与建设网站iis默认网站路径
  • 维修网站建设如何在电脑上重新装wordpress
  • 西安网站建设资讯app外包网
  • 高端网站设计培训机构今天有哪些新闻
  • 酒店 深圳 网站建设wordpress 插件 免费