missionary

Andrew Wilcox 2024-04-25T00:53:47.623979Z

Is initializing a semaphore with 0 tokens expected to work? (I'd expect this to wait at the m/?, but 0 seems to act more like ##Inf)

(let [sem (m/sem 0)]
  (m/? sem)
  (println "acquired"))

acquired

leonoel 2024-04-25T09:43:39.996119Z

it's currently undefined behavior, do you think it should be defined ?

Andrew Wilcox 2024-04-25T09:55:43.134429Z

I was working on a priority queue, where tasks are run one at a time, and when the current task has finished it pulls the highest priority task from the queue. So I needed a way of notifying when a new task had been added to the queue so that the task runner could unblock when the queue was no longer empty. An m/sem seemed like the simplest facility since no data needs to be transmitted, just that another task has been added; although it may be more than is needed since I don't need to count the number of messages in the queue, just whether it's empty or not. If I was going to use a sem I'd need to start at zero since the queue would initially be empty. But I switched to sending nil through an mbx which worked fine. I don't know anything about semaphores aside from reading the Missionary documentation on m/sem so I don't really have an opinion on what it should do, though if 0 is invalid that would be good to mention in the documentation.

leonoel 2024-04-28T19:37:06.647669Z

https://github.com/leonoel/missionary/issues/111

joshcho 2024-04-25T04:36:41.902399Z

curious about the design of missionary. the language-native dsl feels a lot simpler than monadic approach, but from a theoretical, abstract perspective, are there monads under the hood? would that be the correct mathematical framing?

Andrew Wilcox 2024-04-25T07:57:03.380089Z

I can't say about monads, but in terms of the design, https://github.com/leonoel/task and https://github.com/leonoel/flow are excellent references, if you haven't seen them already.

❤️ 1
joshcho 2024-04-25T11:38:09.714759Z

oh this is great! thank you