Skip to main content

Parallel execution

Introduction

You might have asked yourself what would happen if two or more actions were to be connected to the same OUT port. You could use the title of this chapter to guess it!

Creating threads

You're free to connect as many actions you want into the same OUT port, which would effectively create that many threads (Goroutines). Once a new thread is created, the execution flow rules apply to each thread on it's own, meaning that one thread might get rerouted through a KO port and quit, while another thread could keep running through it's "happy path".

Keep in mind that once a new thread is created it will effectively bifurcate the execution flow into as many execution flows as threads there are, which means that all the actions that are shared along the execution path of each thread will get executed as many times as threads exist.

Joining threads

Sometimes you'll want to bifurcate the execution path of your blueprint and end up with two different threads, each one of them executing on it's own what's left of the blueprint after the bifurcation. This is useful when you want the same thing to be performed N number of times in parallel.

But you might also want to "join" these threads at some point, wait for all of them to finish executing their execution path and then end up with a single thread. This is what the Join threads action does.

Variables scope

Both action variables and user defined variables have scopes. They are not globally accessible from anywhere in the blueprint; they have specific scopes and they are accessible only from execution paths within that scope.

Explained with simple words, variables are accessible from any point in an execution path only if that execution path can be traversed backwards and the point were the variable was created is reached.

Variables and threads

Each newly created thread will inherit and copy all the variables that are located on the execution path it has been created from. From there on, each thread will be able to create new variables or modify the variables it inherited, but these modifications won't affect other threads.

If several threads are joined, all the variables from each one of the joined threads will be put in the scope of the new execution path created by the "Join threads" action.

If several threads defined a variable with the same name, once all threads have been joined, the variable will contain the value of the last thread that finished it's execution and reached the "Join threads" action.