# Concurrency

Midio supports concurrency by allowing you to split a[ process](https://docs.midio.com/midio-docs/the-midio-engine#processes) 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.

<figure><img src="https://1896308808-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRdFpuRAnTVYgmlCXLLou%2Fuploads%2FaBwcaJnuTSsnThTXaWYl%2Fimage.png?alt=media&#x26;token=7970eec2-5b2f-486e-86b5-5b56c8d0c78f" alt=""><figcaption></figcaption></figure>

## 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`.

<figure><img src="https://1896308808-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRdFpuRAnTVYgmlCXLLou%2Fuploads%2FTSln2tosaiZqqlJMh5Bl%2Fimage.png?alt=media&#x26;token=aa990918-ffe7-49c7-abbe-a05d90528b5f" alt=""><figcaption></figcaption></figure>

## 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.

<figure><img src="https://1896308808-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRdFpuRAnTVYgmlCXLLou%2Fuploads%2FImCzvEeSgvnmZLm9w6Ao%2Fimage.png?alt=media&#x26;token=45e847c1-cbcc-4214-9ee9-9c14da9de107" alt=""><figcaption></figcaption></figure>
