Extending functionality of clojure core.async
Asked Answered
M

1

5

Is it recommended to extend the functionality of core.async with my own asynchronous functions?

The asynchrony of channels is handled by put! and take! which accept callbacks, but the protocols are nested in the async.impl.protocols namespace. Does impl mean stay out! in this case, or is it okay to implement them?

For example, I could wrap a netty channel or a java socket as a ReadPort and a WritePort.

Melisma answered 31/10, 2013 at 6:8 Comment(4)
Well, there used to be an answer here that said essentially "go for it!" It seems like that's been retracted.Melisma
I'd say do what you want!Labyrinthine
@Labyrinthine but, if the protocol is hidden, then there's a greater likelihood of it changing without notice. That would be a bear.Melisma
I removed my answer because I misunderstood the question. I thought you were asking whether using, not implementing put! and take! was fine. But I have no idea whether you are allowed to implement them on your own.Ashti
P
7

The intention of the core.async protocols is to serve as implementation hooks for implementing your own buffers, channels, ports, etc. They exist under impl as they are part of the implementation, not the public user API.

The team considers them to be open to change until a non-alpha version of the library is released (I have no timeframe on that). From async's release until now the protocols have not changed, however there is at this moment a breaking change in process specifically to put! and take!.

If you're willing to deal with catching changes for now, feel free to implement as you wish.

Tim B has spent quite a bit of time looking at connecting async channels to the network and it is very challenging to do while retaining the channel semantics. The recommended pattern right now for this is to use dedicated threads that talk to network I/O and communicate "at the edge" with the channels in the application (probably using put! and take!). This pattern does not require implementing the internal protocols.

Parvenu answered 5/2, 2014 at 5:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.