This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-09-05
Channels
- # announcements (2)
- # babashka (19)
- # beginners (14)
- # biff (10)
- # calva (23)
- # clojure (49)
- # clojure-europe (15)
- # clojure-nl (3)
- # clojure-norway (25)
- # clojure-seattle (1)
- # clojure-uk (4)
- # clojurescript (7)
- # data-science (6)
- # datahike (3)
- # datomic (1)
- # emacs (13)
- # events (2)
- # fulcro (3)
- # graalvm (13)
- # hyperfiddle (32)
- # leiningen (4)
- # lsp (38)
- # malli (1)
- # missionary (34)
- # nbb (28)
- # off-topic (42)
- # other-languages (5)
- # portal (8)
- # practicalli (1)
- # re-frame (3)
- # releases (1)
- # ring (7)
- # shadow-cljs (13)
- # sql (3)
Hello ๐ I'm trying to use missionary to launch a few dozen independent processes. Those processes should do something on startup and then also execute certain tasks in specified intervals. Ideally I'd also be able to introduce some offset between launching those processes. After a fixed interval of time I'd like to shut down all processes. I think missionary is the right tool for this but I'm not entirely sure how to structure it...
could you describe an MVP that would form the basis to improve towards the final solution? Or extend the problem description, right now the definition is too vague to propose solutions. E.g. what do the tasks do on startup (computation, IO), how are the specified intervals specified (is it an external input, is it known AOT)
Hey, and sorry about the vague-ness ๐ The startup is IO (network/promise) and the intervals are defined AOT.
I'm trying to generate load on a UI system for performance testing. This effectively means simulating users in a chat via database writes. The users activity can be described as follows: 1. joining the chat = "startup" 2. sending messages while active 3. sending presence pings while active
So each user is basically a task that continuously executes some simple IO. I was thinking I need to use a flow for the "executing stuff in intervals" but I'm wondering if maybe this also could just be cancellable tasks.
you can run this from the comment block. It concurrently spawns 10 tasks that do some work (you can see the prints in stdout) and shut down after provided ms
> I was thinking I need to use a flow for the "executing stuff in intervals" but I'm wondering if maybe this also could just be cancellable tasks
indeed tasks can work as well, in the above prototype loop/recur
with an m/sleep
inside acts as a long-running task
yeah the loop/recur is nice actually. Thanks for this I think I'm understanding most of it even ๐
Ah โ one thing I just noticed I dropped is the m/via m/blk
but I think since I'm in cljs-land it probably isn't relevant? (there's no impl for it in missionary.cljc)
glad to help! m/via
is for offloading cpu/io-intensive tasks on a JVM thread, so yes, irrelevant in cljs context
erm... as I now incorporated the promises into startup-task
things stopped working and now I'm like "how do I convert a promise to a task" but can't find anything in the docs
if not then https://github.com/leonoel/missionary/wiki/Task-interop#futures-promises-1
ultimately they're from a third party library. I would try to convert my functions to tasks, but in the end I'll need to interop with promises.
If you haven't already stumbled across https://github.com/leonoel/task, I'd give it a read โ it helped me intuit things like promise interop a bit better
there is also the counterpart https://github.com/leonoel/flow
if you want to fully understand the await-promise
implementation I opened a https://github.com/leonoel/missionary/discussions/61 a while back where Dustin links to his https://gist.github.com/dustingetz/d3fb5338b43ef86df5f97387f1d5e249#file-await_promise-clj
I remember reading the task spec a while ago actually. And the reasoning for await-promise
also makes sense. At the same time it would be nice if it was a bit more out-of-the-box supported to work with promises. In JS it's just the bread and butter of everything
I think Leo tries to keep missionary small and free of helpers. In any case, today you can copy the impl from the wiki page into your codebase ๐
electric repo has a contrib.missionary-contrib ns where i collect the helpers, send them to me and i will add them. will break it out at some point. i try to review all contrib helpers with Leo first
I just ran into a slightly surprising error handling behaviour that I'd like to understand... ๐งต
With this kind of code I could see {:sending uid}
being tapped and then :sent
would never show up. The overall thing (wrapping this with m/race
) would exit successfully. Upon further investigation it turned out that there was a synchronous error in post-chat-msg!
that was not surfaced. await-promise
was never called, instead the .add
line caused the exception.
Interesting... after a REPL restart I can't repro this...
Even if the first completed input fails? Would this mean combining m/race
with m/sleep
would always succeed?
yes. as long as there is still an input running, the race is not over (because there is still a chance to succeed)
Gotcha, what would be the recommended way to fail fast if something fails?