美文网首页
Go版本Compose

Go版本Compose

作者: ashyanSpada | 来源:发表于2021-05-01 17:10 被阅读0次

    写了个Go版本的,有时间再补充。

    type Compose struct {
        handlers []func(ctx context.Context, next func())
        ctx      context.Context
    }
    
    func (c *Compose) New(handlers []func(ctx context.Context, next func())) *Compose {
        c.handlers = handlers
        return c
    }
    
    func (c *Compose) Do(ctx context.Context) {
        c.dispatch(0)
    }
    
    func (c *Compose) dispatch(i int) {
        c.handlers[i](c.ctx, func() {
            c.dispatch(i+1)
        })
    }
    

    相关文章

      网友评论

          本文标题:Go版本Compose

          本文链接:https://www.haomeiwen.com/subject/btaarltx.html