How to <! a java Publisher interface?
something like this:
(defn as-async
[^Publisher p]
(let [promise-chan (async/promise-chan)]
(.subscribe p
(reify Subscriber
(onComplete [this]
(async/close! promise-chan))
(onNext [this t]
(async/put! promise-chan t))
(onSubscribe [this s]
(.request s 1))))
promise-chan))
There is a library for that?Extend the ReadPort protocol?
You need to use >!!
(oh, didn't notice the single use promise chan)
Actually what you would do is use put!, But pass a callback that calls request 1 after the put! conpletes
And then don't use a promise chan
Then you'll have a pretty generic subscriber to channel adapter
You could extend readport to Publisher, but then you are extending a protocol you don't own to a type you don't own, which is generally a bad practice