Discussion about this post

User's avatar
Jan Alexander Steffens's avatar

I think your JavaScript example on concurrent mutation is wrong. Because `doSomethingElse` is not an async function or promise you await, it doesn't matter how long it takes. `newScore` cannot progress past its own await of the timeout while the code that launched it is still running. So the value of `profile.score` at the end is always `3`.

The code would have the behavior you describe if it read `await doSomethingElse();`.

Expand full comment
Ben Munat's avatar

Nice write up! There's a couple bugs in the Scores module though... a lowercase "p" in `Process.get` and the `score` var isn't initialized. But it's a nice topic to ponder and its great to share this information with folks new to Elixir. The power of the first-class, baked-in Process in BEAM languages is awesome. Ironically though, even though I've written lots of GenServers I haven't yet had a need to reach for the Process dictionary. I suppose it's just not the sort of problems I've worked on. I try to stick with just mutating pipes, from input to result, and avoid in-memory global state. One of these days, I'm sure I'll have to. Cheers!

Expand full comment
6 more comments...

No posts