0.6.0
Newly using promise-chan for callbacks
WARNING: this is potentially a breaking change!
I decided to change semantics of returned core.async channels from async api calls. In versions prior 0.6.0 they returned normal core.async channel chan and the channel was closed after receiving a result value. Newly since this version they return promise-chan instead and the channel is not closed. Please read more about semantics of promise-chan here.
Under normal circumstances you should not need to rewrite your existing code, promise-chan is just more flexible and allows multiple consumers of a single API call. Let's see some examples:
(let [api-call-channel (chromex.ext.tabs/get tab-id)]
(go
(if-some [result (<! api-call-channel)]
(do-something-with result)
(report-tab-not-found))))(let [api-call-channel (chromex.ext.tabs/get tab-id)]
(go
(if-some [result (<! api-call-channel)]
(do-something-with result)
(report-tab-not-found))))
(go
(if-some [result (<! api-call-channel)]
(do-something-else-with result)
(report-tab-not-found))))Let's compare behaviour of those code snippets under old and new circumstances.
We have a call to a chrome async api. In the first code snippet there is only one consumer of the result channel. In the second snippet there are multiple consumers waiting for the same answer.
Please note that the first snippet works the same under old and new version of the library. But the second code snippet does not work as expected under old version of the library.
Prior version 0.6.0 with chan:
api-call-channelis achanapi-call-channelreceives callback value as result and then closes- that means that only one of the go blocks receives the
result, the other one will receivenil
Since version 0.6.0 with promise-chan:
api-call-channelis apromise-chanapi-call-channelreceives callback value as result and then DOES NOT close- that means (thanks to promise-chan semantics) that both go blocks receive the
resultvalue
Also note that in case of an error the channel gets closed and both go blocks execute their else branch.
Reverting to the old behaviour
I believe code using multiple consumers wasn't easily possible before so there is a low risk of breakage. If someone used multiple consumers they had to create their own "shared" channel (e.g. using promise-chan and manage it on their own).
If you need to revert to old behaviour. Please look at this commit. You can configure chromex to use your custom implementations of :callback-channel-factory and :callback-fn-factory. By swapping them for old implementation you can easily get back the old behaviour.
API update
Regenerated APIs to match Chromium @ 2896ec3.
Notable commits:
0e925e2 use promise-chan for replacing callbacks
f13669a introduce last-error-args state
All new changes: v0.5.16...v0.6.0