Skip to content

Instantly share code, notes, and snippets.

@RutledgePaulV
Created September 5, 2017 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RutledgePaulV/ec88ef7c8d168342a1c47f14b52d1c0f to your computer and use it in GitHub Desktop.
Save RutledgePaulV/ec88ef7c8d168342a1c47f14b52d1c0f to your computer and use it in GitHub Desktop.
(defn attach-channel-cleanup [chan f]
(add-watch (.closed chan)
"channel-resource-cleanup"
(fn [_ _ old-state new-state]
(when (and (not old-state) new-state)
(f))))
chan)
@RutledgePaulV
Copy link
Author

Used to make sure that any resources driving the inputs to the channel (like a network connection) are cleaned up when the channel is closed (regardless of who closes it or when).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment