Concurrency

Midio supports concurrency by allowing you to split a process into several concurrently running processes.

There are three main functions for doing this. The simplest one is Std.Spawn which simply splits the current process into two. The two processes can then be merged back together using Std.Merge with Child Process. The result input lets you pass a value from the child process back to the parent process.

Spawning many processes

Sometimes it is convenient to spawn a whole bunch of processes, to for example perform some operation for each item in a list. There are two functions for this in Midio, Spawn Processes from List and Spawn Processes from Range. The first acceps a list as input, and spawns a process for each item in the list, passing each item to the spawned process. The other spawns one process for each index in the provided range.

Both these functions can be merged again, but this time using Merge All.

Example

Here is a more realistic example, where we perform a translation using the open-ai package on a bunch of lines in a list, from english to spanish.

Last updated

Was this helpful?