寫了個(gè)Go版本的幕袱,有時(shí)間再補(bǔ)充。
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)
})
}