scalaz/scalaz-stream — pull request #20 by pchlupacek (2013-09-02 14:16:31+00:00)
Title: Proposed change in streams.async

I have used current async implementation and found it has some race condition probabilities either in code itself or if you are using it in different contexts.

Therefore I suggest following PR to eventually fix these and add new functionalities. To summarise, following changes are proposed:

- The Ref has now more like java.util.concurrent.AtomicRef signature, namely:
- added getAndSet method
- added compareAndSet method

- Added async variant of Ref via Ref.async

- Instead on combining the Ref, ref is now supporting two basic streams, the continuous stream and discrete stream. Any other Refs source stream I believe can be made by using various combinators on these streams in library.

- Discrete stream of `Ref` is now based on serial stamp, instead on waiting just on `Set` event. The previous solution had a race condition when there was one or more Set`s between two successive Get's that were not catched and eventually leaded in deadlock. This introduction of stamp allows 2 different sources, namely `toStampedSource` and `toStampedDiscreteSource`. Also discrete stream now has contract that it emits Get when the value changed, instead on Set.

- Removed `event` and `changed` combinators from async, hence their streams can be now obtained directly from `Ref`.

- `Signal` is now just enhanced `Ref`.

- `Signal` has now all changed, discrete, continuous, changes processes defined as factory methods (instead of vals) to create independent processes, that allows them to be run in different context on different threads.

- Implementation of actor.ref changed in order to support new functionality. I have also migrated Modify and Set messages to one, and Close and Fail to one, hence they are almost same in signature

I have added some specs that are trying to verify the functionality. I think we shall also consider to add specs2 as testing framework, because writing the concurrent and more complex integration tests in ScalaCheck is a nightmare (or maybe I just don't know how to do it properly :-))

Please let me know what do you think