Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should clojure core.async channels be closed when not used anymore?

Close method (at least in java world) is something that you as a good citizen have to call when you are done using related resource. Somehow I automatically started to apply the same for the close! function from core.async library. These channels are not tight to any IO as far as I understand and therefore I am not sure whether it is necessary to call close!. Is it ok to leave channels (local ones) for Garbage Collection without closing them?

like image 794
Viktor K. Avatar asked Mar 05 '15 21:03

Viktor K.


1 Answers

It's fine to leave them to the garbage collector unless closing them has meaning in your program. It's common to close them as a signal to other components that it's time to shut themselves down. Other channels are intended to be used forever and are never expected to be closed or garbage collected. In still other cases the channel is used to convey one value to a consumer and then both the producer and the consumer are finished and the channel is GC'd. In these last case there is no need to close them.

like image 94
Arthur Ulfeldt Avatar answered Nov 09 '22 00:11

Arthur Ulfeldt