Svelto.Tasks
Run Asynchronous promise compliant tasks in Serial, Parallel and from other threads exploiting full continuation.
FAQ:
What is Svelto.Tasks?
Svelto.Tasks is part of the Svelto Framework. It allows to run yielding IEnumerators in Serial, Parallel and between threads. It’s much more than it sounds, as the unique continuation feature allows to switch seamlessly between schedulers so that tasks can run at different times following the same simple flow. The ITaskRoutine interface allows to use Promises compliant tasks too.
Who’s using Svelto?
Svelto is the official framework of Freejam, so it’s extensively used to run Robocraft, Robocraft Infinity and Cardlife (plus new upcoming titles). I know other companies are using it, but unluckily I am not getting much feedback. Please let me know if you use it, as I’d like to be in contact.
Do you offer support for Svelto?
Svelto is open source and offered as it is. Unluckily I don’t have much time to invest on it beside what I need for our projects, but I will be glad to answer your questions as they come. Of course, being open source and hosted on github, feel free to send me pull requests.
OK, but what can I do with it?
It’s not simple to explain in few words the potentiality of the framework as it can easily be confused with many similar libraries out there. Svelto.Tasks contains many unique features. I tried to show them through my articles and the set of examples and unit tests that ship with the library. However I understand that, without a proper documentation, is hard to wrap one’s head around it at glance. I strongly suggest to experiment with it starting from what I offer, then I will be here to try to help whenever I can.
What can I do that I can’t do with Unity already?
Better question. I will list the unique features, from the most obvious to the less ones:
-
Allows to run yielding IEnumerator (you should see them as asynchronous tasks) on classes that are not Monobehaviour. For example: MyEnumerator.Run(), will run the enumerator on the UpdateMonoRunner scheduler through an always available static extension method. Fire and forget it.
-
There are several Schedulers available: UpdateMonoRunner, LateMonoRunner, CoroutineMonoRunner, StaggeredMonoRunner, PhysicMonoRunner. You can explicitly choose the runner to run your IEnumerator on using the static extension RunOnSchedule. For example: MyEnumerator.RunOnSchedule(new LateMonoRunner()) or using the standard ones MyEnumerator.RunOnSchedule(StandardSchedulers.physicScheduler).
-
Because of the Marshalling that the normal StartCoroutine must perform, using Svelto.Tasks should be always faster in every occasion.
-
You can yield very complex flow of tasks exploiting continuation. You can yield a serial collection of tasks, from a parallel collection of task, from a normal IEnumerator.
-
You can yield everything from other threads using the MultiThreadRunner. It works exactly like the other runners. However you must use the ThreadSafeRunOnSchedule() method instead.
-
A task running from the standard UpdateMonoRunner can yield and wait for a task running on a MultiThreadRunner. Synchronization between threads become much easier to manage.
-
Through the interface ITaskRoutine, you can setup OnFail (exception happened) and OnStop (task stopped explicitly) callbacks. All the other promise-like features are available using the same logic that the .Net task library uses (more on the examples)
-
Well, as I said, much more can be done, but it must be tried to get it properly. Please check articles and example for more insights.
-
Designed to be fast, light and allocation free.
Further Resources:
My blog: http://www.sebaslab.com/
Main Article: Svelto TaskRunner - Run Serial and Parallel Asynchronous Tasks in Unity3D - Seba's Lab
Article on optimizations: Svelto.ECS+Tasks to write Data Oriented, Cache Friendly, Multi-Threaded code - Seba's Lab
Github: GitHub - sebas77/Svelto.Tasks: Svelto Tasks - C# promises compliant multi-threaded tasks runner (many examples of usage and unit tests included)