We can't find the internet
Attempting to reconnect
Something went wrong!
Attempting to reconnect
Analysis Summary
Worth Noting
Positive elements
- This video provides a clear, low-level explanation of how Erlang's message passing and process monitoring work together to ensure data order and fault tolerance.
Influence Dimensions
How are these scored?About this analysis
Knowing about these techniques makes them visible, not powerless. The ones that work best on you are the ones that match beliefs you already hold.
This analysis is a tool for your own thinking — what you do with it is up to you.
Related content covering similar topics.
Episode 1: Handling Unexpected Errors Gracefully
Exploring Elixir
Exercism Summer of Sexp - solving challenges with Clojure
Practicalli
Optimizing the BEAM's Scheduler for Many-Core Machines - Robin Morisset | Code BEAM Europe 2025
Code Sync
Everything you need to know about FFI in Gleam
Isaac Harris-Holt
IEx's Hidden Superpowers - Brett Beatty | ElixirConf US 2025
ElixirConf
Transcript
today on the bean Channel I want to heard about one that's sort of basic Erlang examples parallel map now parallel map is one of those you know I think exercises every airline or illiterate developer should write I'm going to present it here inner line but the elixir code would be exactly the same basically and the idea is you know map is you're taking a list of items and you apply some function to each of them and then a new list now normally map would operate sequentially and in fact in many cases that's what you want to do well earlier you know we should provide a low overhead for creating new processes it's not zero so you should be aware of that and you know you might also want to do something clever like limit the number of processes so going to only create 50 total maximum 50 it's a just arbitrary number that's beyond us for this video I'm also you could also use more specific elixir features like tasks and so agents and stuff that a I'm not presenting those this is the very simple what we want to do is create a P map function and should write the regular from regular map take a function and a list of items to map over now what you'd want to do is first of all do a spawn and then you're going to create a little wrapper function in that which can be execute which is going to take the process ID of the the master process the iterator function and then the element of the list and it's going to create an element create a process for each of those and then you'll get back a receive that says or that then the execute function will run that function over the element and send back a message to the initial process with the process ID and the result now that process ID is very important we're in take advantage of Erlang's I don't imagine here in a second you will notice that we stored a list of process IDs up at the top there that's important because if we didn't do that and we just said okay just get all the way till they all come back first of all you'd have no way of knowing how many you do expect but second when they don't come back in a rant in an arbitrary order given n elements in the list there would be two to the N possible orderings and it would come back and presumably a different ordering every time or it was potentially so so what we're going to do is use the gather function here to receive them in order so you can see that we say we take the first item off of that list of PIDs and we wait for and receive for an element to match that and then we take the next one in the next or the next one in that way no matter what order of the processes finishing they're going to always come out in the right way because we're going to pattern match through the through the list until we get the right order so you hope to think about it it happens it Imagi Khalif falls out now the problem with this initial implementation I showed you is that if something goes wrong in one of those little circle if you took the square root of a negative number it would die that process would die but then the master process would just hang there waiting forever so we want to account for that and fortunately we have a good way to that which we can say receive so in our list map we can say instead of spawn spawn monitor now we're going to get back at pin and a reference but we can just leave that the rest that code the same I'm also going and the gather function going to add a timeout and we're gonna say 500 behalf of site you can change that value whatever you want it doesn't matter and then in the gather function we're going to change that receive so instead of highly P and we're going to pin an M ref the reference to the monitor and in the case it works correctly we're gonna leave that exactly the same that doesn't but in the case this one goes wrong we're gonna get a different message we're going to get down MRAP process pin reason and a reason will be reason to think that in that case we're going to call exit error reason you can also just have a return that we error if you want but I find this better and we're gonna also add a timeout there where she didn't timeout the exit Appy map reason change that if you want well so that is that monitor we can't top now so run it and so we take this example here where we are in over a list of them when you use the square root functional the list of numbers if we run it over include a negative number in that list we are going to get it you get an error because square of a number well it gives us an ITIN theoretically is magic so this was any sort of error condition simple you get back for error through it all that error what was the initial value that clouds the error to that much food I didn't do that possible well so you know oh it was the negative number that caused the problem or it was sorry I hope that was useful to you as an exercise to the science Phil we ready sir or enhance it in some other way feel free to steal this code
Video description
Parallel Map is something that if you do Erlang or Elixir you will want sooner or later. This is a brief example of how to do it. This touches on many of the features of the BEAM's concurrency model. Elixir Deployment Email Course - https://elixirtraining.org/release_email_course.html If you would like my help getting started with Elixir or Erlang feel free to book a time to talk to me https://calendly.com/zkessin/elixir To Suggest ideas for Videos: https://goo.gl/forms/nnUH2HBvOHbzsVuu2 Follow me on twitter https://twitter.com/zkessin LinkedIn: https://www.linkedin.com/in/zacharykessin/