Example #1
0
func (ch fooChan) SubscribeTo(ctx *pubsub.Context) error {
	rfn := func(v interface{}) bool {
		if v == ctx.Done {
			close(ch)
			ctx.Close()
			return false
		}
		ch <- v.(foo)
		return true
	}

	ctx.Buffer.ReadTo(rfn)
	return nil
}
Example #2
0
func (fn fooFunc) SubscribeTo(ctx *pubsub.Context) error {
	rfn := func(v interface{}) bool {
		if v == ctx.Done {
			ctx.Close()
			return false
		}

		fn(v.(foo))
		return true
	}

	ctx.Buffer.ReadTo(rfn)
	return nil
}
Example #3
0
func (ch fooChan) PublishTo(ctx *pubsub.Context) error {
	go func() {
		defer ctx.Close()

		for {
			select {
			case v, ok := <-ch:
				if !ok {
					return
				}

				ctx.Buffer.Write(v)
			case <-ctx.Done:
				return
			}
		}
	}()

	return nil
}