You can think of a Task like a function that maintains state automatically. However, instead of using returning values with 'return x', you use 'produce(x)' instead.
This will cause execution of the Task to pause until it is called again. Tasks are called with the 'consume' function, which will in turn return the value given by the 'produce'. The official Julia documentation gives code examples of how to create and use tasks. In the case of the documentation, a task is returned from within a function. The variables defined in the function get bound to the Task returned, which in turn are modified between each call to consume. Julia allows you to also use Tasks as iterators. You can get similar behavior with returning a function from a function. The inner function will be bound to the outer function's variables and can modify them. If the variables are scalars, they will be copied, if they are complex types a reference is created.
