3 ms·
This might be a stupid question but how can the site run multiple maze generation algorithm at the same time? My understanding is that javascript is single thre
by hamsterbooster 6y ago
This might be a stupid question but how can the site run multiple maze generation algorithm at the same time? My understanding is that javascript is single thread.
- ChrisAntaki 6y agoBy using the event loop, with functions like setTimeout
- jbattle 6y agoReally good question actually! I peeked at the javascript and it looks like when you hit `run`, it is calling the step at a setInterval (if I'm reading this right, as fast as the browser can call run) So at the end of each run call, the interpreter figures out which setInterval timer to execute next and has the chance to pick other mazes. (I don't know much about how the JS engine resolves which "not quite thread" gets run next when there are multiple candidates)
- hamsterbooster 6y agoThanks! I ran multiple maze at the same time and time it and it seems like the maze ran just as fast as running only one maze at a time. If the interpreter can pick other maze, should it take longer? Did I miss anything here?
- rejschaap 6y agoThe maze generation is slowed down to visualize what is going on. Most of those mazes can be generated in a few of milliseconds.