puniverse / pulsar

Fibers, Channels and Actors for Clojure
http://docs.paralleluniverse.co/pulsar/
Other
911 stars 53 forks source link

Make channels lazy-seqs #1

Closed pron closed 11 years ago

pron commented 11 years ago

Also, see #2 .

pron commented 11 years ago

Possibly requires a suspendable implementation of LazySeq. Certainly one of take.

pron commented 11 years ago

This turned out to be harder than expected. The problem wasn't that the bodies of the lazy-seqs in, say, filter and map, are not suspendable. Actually, resuming them would have been fine. The only functions that really required instrumentation are those that recur like doall.

The problem was much more incidental. First, the lazy-seq macro tags the function with :once which causes refs to closure to nullify during first call. This means that upon resumption (or re-run) the function wouldn't run properly. However, a message on the clojure mailing lists says that the :once tag on lazy-seq is unnecessary. So that's just unfortunate. This resulted in the need to redefine lazy-seq as well as the functions using it.

The second problem was in the LazySeq class itself. The function seq nullifies sv before looping on ls. If it had only nullified it later, it would have been fine (because suspension happens in sval()). This resulted in the need to define a new LazySeq class.