Open daveliepmann opened 11 months ago
I ended up "writing" my own with-open, but then I soon realized that half the things I wanted to with-open were actually closed with .cancel and not .close. And then some more had to be .dispose'd...
And creating a closable protocol would require lots of tactical extensions.
I suspect that with-open
must stay true to its original spirit of relying on conventions and not interfaces.
Something like?
(with-open [controller (xxx) :close .dispose] ...)
I propose adding with-open
to CLJD with the following deviations from CLJ:
1/ allow for keyword options in the bindings vector (options apply to the previous binding)
2/ only supported option is :close
whose value is a form into which the resource is threaded (as per ->
). Default value is .close
. When the close is itself async, the user would have to write :close (-> .terminate await)
. Is it common enough to mandate an :await-close
option? I don't think.
3/ allow destructuring in bindings (useful for example with StreamController where stream and sink fields have to be used). It doesn't make sense in CLJ where there's no :flds
destructuring.
However with-open
doesn't cover Dart streams. We need something like Dart's await for
. There are at least two distinct macros/fns: one to reduce (should we expect the reducing function to return a future? If not should we provide two reduce variants? Should we also consider transduce? Or should we go the areduce
way?) and one to perform side-effects (dostream
to riff on doseq
).
Related #287
Describe the bug
with-open
will not compile.Does your problem persist after
clj -M:cljd clean && flutter clean
? YesTo Reproduce Steps to reproduce the behavior:
with-open
form. It breaks with anywith-open
form but the simplest I could invent was:["dart:io" :as io]
to namespace:require
s(with-open [client (io/HttpClient)] (str client " foo"))
Expected behavior
with-open
should compile, create its bindings, and then.close
the bindings