I'm using Om for the client side and through the lifetime of the application many components gets mounted/unmounted. When mounted, various channels are opened (in go blocks). And I'm planning to use IWillUnmount to close them too. But first, my questions are: What happens to unclosed channels? Do the resources they used get released? Not closing channels (when unmounting components) can degrade the browser performance in the longrun? Thanks.
--
Note that posts from new members are moderated - please be patient with your first post.
---
You received this message because you are subscribed to the Google Groups "ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojurescrip...@googlegroups.com.
To post to this group, send email to clojur...@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.
https://groups.google.com/d/msg/clojure/Zr1FmmE2cpQ/B_6MV2sTP8wJ
Thanks for the explanation. Would you be able to provide a code example that demonstrates how to properly clean up a pub/sub watcher within a component's IWillUnmount lifecycle method?
You received this message because you are subscribed to a topic in the Google Groups "ClojureScript" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojurescript/_a5dPeElqG4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojurescrip...@googlegroups.com.
(defmixin go-loop-aware
(init-aware [owner]
{:chans {:mounted (async/chan)}})
(will-unmount [owner]
(async/close! (om/get-state owner [:chans :mounted])))
(go-loop-aware [owner read-chan callback]
(when (exists? js/window)
(let [mounted (om/get-state owner [:chans :mounted])]
(go-loop []
(when-some [v (first (async/alts! [read-chan mounted]))]
(callback v)
(recur)))))))
I like the kill channel solution better personally since like Daniel point out, it doesn't require the read-chan to be owned or controlled by the component.
When [:chans :mounted] is closed, the go-loop exits. I always use when-some over when-let here since when-let would close the go block if false was ever submitted to your read channel, whereas when-some only evaluates (not= nil)