Go版本Compose
2021-05-01 本文已影响0人
ashyanSpada
写了个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)
})
}