Exemple #1
0
// newCacheManager creates a new manager.
func newCacheManager() *cacheManager {
	m := &cacheManager{
		values:  []*cachedValue{},
		changec: make(chan *cacheManagerChange),
	}
	m.loop = loop.Go(m.backendLoop)
	return m
}
Exemple #2
0
// NewCookieSceneManager creates a scene manager using the cookie
// "sceneID" to identify and manage the scene of a client session.
func NewCookieSceneManager(timeout time.Duration) SceneManager {
	m := &cookieSceneManager{
		timeout:     timeout,
		scenes:      make(map[string]scene.Scene),
		requestChan: make(chan *sceneRequest),
	}
	m.loop = loop.Go(m.backendLoop)
	return m
}
Exemple #3
0
// TestSimpleStop tests the simple backend returning nil
// after a stop.
func TestSimpleStop(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	done := false
	l := loop.Go(generateSimpleBackend(&done))

	assert.Nil(l.Stop(), "no error after simple stop")
	assert.True(done, "backend has done")

	status, _ := l.Error()

	assert.Equal(loop.Stopped, status, "loop is stopped")
}
Exemple #4
0
// TestDeferredError tests an error in a deferred function inside the loop.
func TestDeferredError(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	done := false
	l := loop.Go(generateDeferredErrorBackend(&done))

	assert.ErrorMatch(l.Stop(), "deferred error", "error has to be 'deferred error'")
	assert.True(done, "backend has done")

	status, _ := l.Error()

	assert.Equal(loop.Stopped, status, "loop is stopped")
}
Exemple #5
0
// StartLimited creates and runs a new scene with an inactivity
// and an absolute timeout. They may be zero.
func StartLimited(inactivity, absolute time.Duration) Scene {
	s := &scene{
		id:          identifier.NewUUID(),
		props:       make(map[string]*box),
		flags:       make(map[string]bool),
		signalings:  make(map[string][]chan struct{}),
		inactivity:  inactivity,
		absolute:    absolute,
		commandChan: make(chan *envelope, 1),
	}
	s.backend = loop.Go(s.backendLoop)
	return s
}
Exemple #6
0
// TestError tests an internal error.
func TestError(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	done := false
	l := loop.Go(generateErrorBackend(&done))

	time.Sleep(longDelay)

	assert.ErrorMatch(l.Stop(), "timed out", "error has to be 'time out'")
	assert.True(done, "backend has done")

	status, _ := l.Error()

	assert.Equal(loop.Stopped, status, "loop is stopped")
}
Exemple #7
0
// TestSimpleKill tests the simple backend returning an error
// after a kill.
func TestSimpleKill(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	done := false
	l := loop.Go(generateSimpleBackend(&done))

	l.Kill(errors.New("ouch"))

	assert.ErrorMatch(l.Stop(), "ouch", "error has to be 'ouch'")
	assert.True(done, "backend has done")

	status, _ := l.Error()

	assert.Equal(loop.Stopped, status, "loop is stopped")
}
Exemple #8
0
func ExampleLoopFunc() {
	printChan := make(chan string)
	loopFunc := func(l loop.Loop) error {
		for {
			select {
			case <-l.ShallStop():
				return nil
			case str := <-printChan:
				println(str)
			}
		}
	}
	loop.Go(loopFunc)
}
Exemple #9
0
// NewScroller starts a Scroller for the given source and target.
// The options can control the number of lines, a filter, the buffer
// size and the poll time.
func NewScroller(source io.ReadSeeker, target io.Writer, options ...Option) (*Scroller, error) {
	if source == nil {
		return nil, errors.New(ErrNoSource, errorMessages)
	}
	if target == nil {
		return nil, errors.New(ErrNoTarget, errorMessages)
	}
	s := &Scroller{
		source:     source,
		target:     target,
		bufferSize: defaultBufferSize,
		pollTime:   defaultPollTime,
	}
	for _, option := range options {
		if err := option(s); err != nil {
			return nil, err
		}
	}
	s.reader = bufio.NewReaderSize(s.source, s.bufferSize)
	s.writer = bufio.NewWriter(s.target)
	s.loop = loop.Go(s.backendLoop)
	return s, nil
}
Exemple #10
0
// Init the behavior.
func (b *tickerBehavior) Init(ctx cells.Context) error {
	b.ctx = ctx
	b.loop = loop.Go(b.tickerLoop)
	return nil
}
Exemple #11
0
// Init the behavior.
func (b *tickerBehavior) Init(c cells.Cell) error {
	b.cell = c
	b.loop = loop.Go(b.tickerLoop)
	return nil
}
Exemple #12
0
func (pa *publicAddress) Init(ctx cells.Context) error {
	pa.ctx = ctx
	pa.loop = loop.Go(pa.publishLoop)
	return nil
}