Fork me on GitHub
#core-async
<
2019-07-14
>
samedhi00:07:14

Is it possible to have a async/chan that will have a side effect run when it is async/close!'d?

samedhi00:07:33

(regards) Trying to figure out how to implement the following documentation

Returns a channel. If a document exist at `reference`, it will be put! upon
  the channel. If no document exist at reference, then `:firemore/no-document` will
  be put! on the channel. As the document at reference is updated through
  time, the channel will put! the newest value of the document (if it exist)
  or :firemore/no-document (if it does not) upon the channel.

  Important: close! the channel to clean up the state machine feeding this
  channel. Failure to close the channel will result in a memory leak.

samedhi00:07:27

Function could instead return a {:chan c, :unregister fx} to allow for cleanup/closing of channel and state machine, but thought it might be cool to just be able to return a channel and let someone just close! it when they are done with it...

markmarkmark01:07:23

@samedhi This may be frowned upon, but you could implement a buffer that does the side effect stuff in the buffer's close-buf! method. then pass that buffer to the channel.

samedhi01:07:09

Very interesting idea. I am going to stick with trying to reason it through with either alt! or mult for now, but I think your solution would work as well. Thank you.

samedhi02:07:21

>>> Your scientists were so preoccupied with whether or not they could, they didn’t stop to think if they should. - Ian

😅 4