3 ms·
Every asynchronous programming API ever created. My program spawns and runs in the main thread. It calls the main function. If it want it to run forever, I'll
by Schwolop 9y ago
Every asynchronous programming API ever created.
My program spawns and runs in the main thread. It calls the main function. If it want it to run forever, I'll stick a while(1) loop in that function.
Now I want to have a particular thing go off and do some work in parallel with that main loop, and when it's done, I want the next iteration of the main loop to pick up on that fact.
Not once have I encountered a sane API for that use-case as easily expressed as those sentences of prose above.
- lod723 9y agoI can think of a couple trivial ways to express this in Erlang/Elixir. You should take a look at them.
- Schwolop 9y agoI concede I've not studied those languages yet - I do hear good things about them though, so I'll take a look next suitable chance I get!
- kls 9y agoYou know I came from a procedural background and struggled and struggled to learn LISP to see what all the fuss was about. It was really hard because I think like you (not that that is bad or good). Anyways, it was not until I heard it explained that procedural code is about time and functional code is about space that it really clicked. It was explained to me as lightning striking, you don't care when the lightning strikes you just care where the lightning strikes, that really clicked for me, my mindset changed and I got it. I don't think it about as easy or simple, I think it is about how our minds are naturally geared. It took me a lot of mental process to get my head around a distance based thinking about code as opposed to a time based but once I did, I find reasoning about where code is called is easier that figuring about when I want it to be called. But it was not the way my mind naturally worked.
- skybrian 9y agoThis sounds like an event loop to me. Have the main loop check a queue for events indicating completed tasks. If nothing is pending, do the default task.