leonoel / missionary

A functional effect and streaming system for Clojure/Script
Eclipse Public License 2.0
636 stars 26 forks source link

Implement custom printer methods #3

Closed lgrapenthin closed 5 years ago

lgrapenthin commented 5 years ago
(def hello-world
  (m/sp (println "Hello, world!")))
(hello-world #(println "success" %) #(println "error" %))

This results in a fiber which (according to repl print) contains an exception that error fn is invoked with 0 args. If I provide one with 0 args, it is invoked along with the success continuatino.

leonoel commented 5 years ago

What happens here : hello-world is run, immediately completes with nil, then the canceller is returned (an instance of Fiber). The REPL tries to find a way to print the canceller, the canceller doesn't know how to print itself, but as it happens to implement IDeref the REPL tries to deref it. derefing a sp Fiber is a garbage operation so an exception is thrown and then the REPL prints the exception.

Quick workaround : don't print a canceller in a REPL, just define it in a var and maybe call it later. Long-term solution : implement custom printer methods for cancellers to prevent the REPL to fallback to deref.

I file it as a bug since it's a major REPL inconvenience.