Example #1
0
// Rcv method of the composed handler.
func (c *ComposedHandler) Rcv(msg bh.Msg, ctx bh.RcvContext) error {
	var err error
	for i := range c.Handlers {
		if c.Isolate {
			rctx := composedRcvContext{RcvContext: ctx, prefix: strconv.Itoa(i)}
			err = c.callRcv(c.Handlers[i], msg, rctx)
		} else {
			err = c.callRcv(c.Handlers[i], msg, ctx)
		}

		switch c.Composer(msg, ctx, err) {
		case Abort:
			ctx.AbortTx()
			return nil
		case Commit:
			ctx.CommitTx()
			return nil
		case Continue:
			if i == len(c.Handlers)-1 {
				if err == nil {
					ctx.CommitTx()
				} else {
					ctx.AbortTx()
				}
				return nil
			}
		case ContinueOrAbort:
			if i == len(c.Handlers)-1 {
				ctx.AbortTx()
				return nil
			}
		}
	}
	return nil
}