lytics/metafora — pull request #86 by schmichael (2014-12-24 01:08:51+00:00)
Title: Stopping a task may block, so make Balance release async

The entire feature was added by calling release(task) in a goroutine.
However this could lead to concurrent calls to Handler.Stop which
previously wasn't possible.

At first I worked around this by tracking "released" as an extra piece
of state on the internal runningTask struct and simply not attempting to
release (or Stop) a task more than once.

However I realized implementors might find multiple calls to Stop a
useful feature. Subsequent calls to Stop could be tracked by a handler
and implemented as a "forcible" stop if the Run method supports it.

I also wrapped Stop in a lock to serialize calls and ease safe Stop
implementation.

I'm not convinced multiple Stop calls is a worthwhile feature, but it's
easier to implement that "released" tracking. We can definitely
implement single-Stop-call semantics and release tracking later if
desired.