joyride

pez 2024-01-19T13:01:08.181489Z

I’m running latest sci-config in a dev version of Joyride, because I wanted access to promesa.core/timeout. However, it doesn’t quite work as I expect it too. This example, from the https://cljdoc.org/d/funcool/promesa/8.0.450/doc/user-guide#delays-and-timeouts:

(defn timeout-test []
    (-> (fn [resolve, _]
          (p/delay 5000 #(do (println "Resolving promise") (resolve :made-it))))
        (p/timeout 2000)
        (p/then #(println "Task finished" %))
        (p/catch #(println "Timeout" %))))
It prints:
Task finished #object[sci$impl$fns$arity_2]
Immediately, and then nothing happens. I expected it to timeout. (And perhaps also resolve, I’m unsure what to expect around that). If I change the slow task to finish before the timeout, say resolve after 1000, I expect it to wait 1000 ms and then print print Resolving promise immediately followed by Task finished :made-it. Am I holding it wrong, or is it misbehaving? (`p/delay` is working as I expect, btw).

borkdude 2024-01-19T13:01:50.717169Z

Can you try the same example in CLJS?

pez 2024-01-19T13:06:39.829459Z

Will do.

pez 2024-01-19T13:07:40.441559Z

It might be some REPL thing. Because it works in the script where I am replacing my own with-timeout wrapper…

borkdude 2024-01-19T13:08:25.891949Z

what is the API of p/timeout?

borkdude 2024-01-19T13:08:44.301539Z

it seems p/timeout just returns the function (of 2 arguments). you gave it maybe?

borkdude 2024-01-19T13:09:22.263209Z

shouldn't you give timeout a promise instead of a function?

borkdude 2024-01-19T13:10:39.281439Z

also p/delay doesn't expect a function but just a value I think

pez 2024-01-19T13:14:07.088199Z

Thanks! This works as a charm:

(-> (p/delay 1000 :made-it)
      (p/timeout 2000)
      (p/then #(println "Task finished" %))
      (p/catch #(println "Timeout" %)))
And I can confirm exact same behaviour from ClojureScript with both my holding-it-wrong code and this one.

🎉 1
pez 2024-01-19T14:47:27.218409Z

Dear Joyriders: https://github.com/BetterThanTomorrow/joyride/releases/tag/v0.0.42 is out. • Bump SCI to https://github.com/babashka/sci/commit/ad79a6c476affd1f8208efbfdba57992a68c8056 (from https://github.com/babashka/sci/commit/39ce36540eb4c2c6adc74c23ea76ac6330ca7835) • More promesa.core support: Bump sci-configs to https://github.com/babashka/sci.configs/commit/3cd48a595bace287554b1735bb378bad1d22b931 (from https://github.com/babashka/sci.configs/commit/0702ea5a21ad92e6d7cca6d36de84271083ea68f) • Bump rewrite-clj to 1.1.47 We were using a rather ancient SCI. 😃 But chiefly it is about sci-configs for promesa.core, which now gives us access to things like p/timeout. Also, the previous version of sci-config exposed promesa.protocols, which are internal to Promesa. This is no longer exposed. If anyone has Joyride scripts using protocols, you will need to stop doing that, or stay on Joyride 0.0.41.

1
🎉 2