Skip to content

Instantly share code, notes, and snippets.

@ashnur
Created May 4, 2020 22:56
Show Gist options
  • Save ashnur/c336b998fbc5d7c7580aa52fe9e827f7 to your computer and use it in GitHub Desktop.
Save ashnur/c336b998fbc5d7c7580aa52fe9e827f7 to your computer and use it in GitHub Desktop.
+ 10 (defhook use-take
+ 9 [channel on-take]
+ 8 (let [cancel-signal (hooks/use-ref false)]
+ 7 (hooks/use-effect
+ 6 [channel on-take]
+ 5 (go-loop []
+ 4 (if-not @cancel-signal
+ 3 (let [msg (<! channel)]
+ 2 (if-not (nil? msg)
+ 1 (do
+ 124 (ontake msg)
+ 1 (recur))
+ 2 (reset! cancel-signal true)))))
+ 3 #(reset! cancel-signal true))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment