Multiple invocations of `on-finished`
dazld opened this issue · 2 comments
I'm not sure what the correct behaviour should be here, but might be worth thinking about a little.
Given the following code:
(let [now (Instant/now)
chiming (chime/chime-at [(.plusSeconds now 1)
(.plusSeconds now 3)]
(fn [time]
(prn :chime (str time)))
{:on-finished #(prn :done)})]
(Thread/sleep 4000)
(.close chiming))
... we can see that on-finished
is called twice:
:chime "2020-09-07T13:52:33.193745Z"
:chime "2020-09-07T13:52:35.193745Z"
:done
:done
This was surprising to me - perhaps on-finished
should have an invariant that it is only ever called once?
Another option is that perhaps the value which on-finished
evaluates to should be delivered to the invocation of close
, meaning the fn can be evaluated once, but value delivered to multiple places...? Seems like this could be useful.
This was surprising to me - perhaps on-finished should have an invariant that it is only ever called once?
agreed!
Another option is that perhaps the value which
on-finished
evaluates to should be delivered to the invocation ofclose
Unfortunately .close
is from java.io.Closeable
, which returns void
, so we can't do this. Reckon it's simple enough to achieve outside Chime - with a separate promise
, maybe?
Cheers for raising the issue 😄