Пример #1
0
func (t *TurnRunnerCoreSuite) OneTurn() {
	manager := NewManager(NewUniqueIDGenerator())
	runner := NewTurnRunner(manager)
	tlsRelease := async.SetAmbientRunner(runner)
	defer tlsRelease()

	done := make(chan struct{}, 0)
	async.New(func() async.R {
		close(done)
		return async.Done()
	})
	manager.runOneLoop()
	<-done
}
Пример #2
0
// AsyncTurn verifies that a parallel turn executed by a Source does run, and that its resolution is
// reflected correctly on the main turn queue.
func (t *TurnSourceSuite) AsyncTurn() async.R {
	src := turns.NewTurnSource()

	syncPoint1 := make(chan struct{}, 0)
	syncPoint2 := make(chan struct{}, 0)

	// Create a truly parallel turn.
	r := src.New(func() error {
		t.Infof("Beginning async turn.")

		// produce sync point 1.
		close(syncPoint1)

		// wait for sync point 2.
		<-syncPoint2

		return nil
	})

	// Create a coop-turn to provide the sync point.
	async.New(func() async.R {
		t.Infof("Beginning coop turn that provides sync point.")
		// Wait for both parallel and coop turns to have started.
		<-syncPoint1

		// Completed the parallel turn.
		close(syncPoint2)
		return async.Done()
	})

	// Cleanup the source.
	return async.Finally(r, func() {
		// Destroy the TurnSource since we don't need it anymore.
		src.Close()
	})
}