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

如何把做的网站与域名连接网站站内推广怎么做

如何把做的网站与域名连接,网站站内推广怎么做,甘肃兰州怎么样,做新得网站可以换到原来得域名嘛作用:用于在go协程中 传递上下文、超时、取消、传值 底层实现:是由互斥锁、channel、map来实现的 互斥锁:保护临界资源 channel: 用于信号通知,比如ctx.Done() map: 保存父ctx下派生的所有子ctx, 父ctx关闭,子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 child's lock while holding parent's 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.ds6.com.cn/news/70703.html

相关文章:

  • 怎样下载软件到电脑桌面上seo营销培训
  • 移动广告平台seo视频教程百度云
  • 上传网站程序是什么网上代写文章一般多少钱
  • 做网站要以单位b2b免费发布信息网站
  • 微站开发直销的八大课程
  • 腾讯企业邮箱域名可以做网站吗湖南网站设计外包哪家好
  • 建筑网站资料排行榜网站自动推广软件免费
  • 中国建筑工程网招标公告seo刷排名公司
  • 网站搭建费用有了域名如何建立网站
  • 有趣的网站网址杭州最专业的seo公司
  • 品牌网站建设小8a蝌蚪淘宝推广平台
  • 静态网站开发课程小程序运营推广公司
  • 狼人最新网站百度客服怎么转人工电话
  • 上海做网站哪家公司好seo排名优化有哪些
  • 福田大型商城网站建设上海网络推广公司网站
  • 网站开发常用的谷歌插件免费网站站长查询
  • 网站字体一般是什么字体经典软文广告
  • 大学专业宣传网站开发课题意义来宾seo
  • 深圳怎么建设网站学设计什么培训机构好
  • 企业门户网站建设重庆网站建设哪家好
  • 兴化网站建设价格网络推广的调整和优化
  • 廉政网站建设的意义小红书关键词热度查询
  • 哪个网站有收藏加购做积分任务保定网站推广公司
  • b站必看的纪录片南通企业网站制作
  • 手机模板网站模板下载网站有哪些seo常见优化技术
  • 没有logo可以做网站的设计吗seo是做什么的
  • 网站建设的社会意义google海外版
  • 做筹款的网站需要什么资质专业培训
  • 大连金州旅游景点有哪些怎么优化网站关键词的方法
  • 图书馆建设网站谷歌优化技巧