Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alts? throws alts! used not in (go ...) block #2

Closed
laurentsenta opened this issue Apr 6, 2017 · 6 comments
Closed

alts? throws alts! used not in (go ...) block #2

laurentsenta opened this issue Apr 6, 2017 · 6 comments

Comments

@laurentsenta
Copy link

Hi,
First, thanks for sharing this lib and the rest of you work (konserve, etc) with the community.

I get an unexpected exception with alts?:

;; http://stackoverflow.com/questions/30766215/how-do-i-unit-test-clojure-core-async-go-macros/30781278#30781278
(defn test-within
  "Asserts that ch does not close or produce a value within ms. Returns a
  channel from which the value can be taken."
  [ms ch]
  (go-try S
    (let [t (timeout ms)
          [v ch] (alts? S [ch t])]
      (is (not= ch t)
          (str "Test should have finished within " ms "ms."))
      v)))

(test-within 100 
  (go-try S 1))

(S is the default supervisor).

Throws:

=> #object[cljs.core.async.impl.channels.ManyToManyChannel]
Supervisor: #object[Error Error: alts! used not in (go ...) block] Error: alts! used not in (go ...) block
    at Function.cljs.core.async.alts_BANG_.cljs$core$IFn$_invoke$arity$variadic (http://localhost:3002/js/testbook.out/cljs/core/async.js:767:8)
    at cljs$core$async$alts_BANG_ (http://localhost:3002/js/testbook.out/cljs/core/async.js:760:35)
    at Function.superv.async.alts_QMARK_.cljs$core$IFn$_invoke$arity$variadic (http://localhost:3002/js/testbook.out/superv/async.js:673:45)
    at superv$async$alts_QMARK_ (http://localhost:3002/js/testbook.out/superv/async.js:667:33)
    at http://localhost:3002/js/testbook.out/budb/test/helpers.js?zx=rxrmkpegur10:623:43
    at http://localhost:3002/js/testbook.out/budb/test/helpers.js?zx=rxrmkpegur10:674:51
    at budb$test$helpers$test_within_$_state_machine__27340__auto____1 (http://localhost:3002/js/testbook.out/budb/test/helpers.js?zx=rxrmkpegur10:695:4)
    at budb$test$helpers$test_within_$_state_machine__27340__auto__ (http://localhost:3002/js/testbook.out/budb/test/helpers.js?zx=rxrmkpegur10:711:72)
    at cljs$core$async$impl$ioc_helpers$run_state_machine (http://localhost:3002/js/testbook.out/cljs/core/async/impl/ioc_helpers.js:93:110)
    at cljs$core$async$impl$ioc_helpers$run_state_machine_wrapped (http://localhost:3002/js/testbook.out/cljs/core/async/impl/ioc_helpers.js:96:63)
    at http://localhost:3002/js/testbook.out/budb/test/helpers.js?zx=rxrmkpegur10:726:67
    at cljs$core$async$impl$dispatch$process_messages (http://localhost:3002/js/testbook.out/cljs/core/async/impl/dispatch.js:20:9)

Using alts! instead behave as expected.

@raycheung
Copy link

Looks like the wrap-abort! inside alts? violates the restriction mentioned here.

@whilo
Copy link
Member

whilo commented Apr 6, 2017

@raycheung Correct. I thought Rich Hickey once said that alts! is a real function, not just syntax (macros), but it is not wrappable and I think one has to treat it as syntax and wrap it in a macro unfortunately.

@lsenta I think this has fixed it d291239. Thanks for reporting! Somehow it slipped through the tests, I have added one for it.

@whilo
Copy link
Member

whilo commented Apr 6, 2017

I will release a new version soon, unless you find other issues. 😃

@whilo
Copy link
Member

whilo commented Apr 6, 2017

@raycheung The function boundary wrapping is a bit cumbersome, but understandable. All JVM libraries supporting fibers (they mention Erjang, I also know it from pulsar) do bytecode transformations. I just wish they had covered error handling in core.async, so wrapping all of it wasn't necessary.

@laurentsenta
Copy link
Author

laurentsenta commented Apr 8, 2017

Thanks for sharing the limitations post and providing a fix for this issue. No other issues on my side, I'll wait for the next release, try alts? again and let you know!

@whilo
Copy link
Member

whilo commented Apr 8, 2017

Fixed with 0.2.6 release :)

@whilo whilo closed this as completed Apr 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants