JavaScript mini TPL library: RunAsync

Having learned about HTML5 Web Worker functionality, and that most of the modern browsers implement it, together with the File API BlobBuilder capability I thought about building a library that resembles C#’s Task Parallel Library, allowing JavaScript to be executed in a background thread, but at the same time, adding the ability to dispatch execution to the UI thread and also invoke callbacks and continuations to a “task”. I figured the dispatcher functionality was important since usually whatever is executed in the background can/probably will need to interact with the UI while executing. Also this opens a door to use UI frameworks such as jQuery and/or any other DOM access. The problem of passing state while dispatching to the UI thread still exists, but it’s on my queue to be solved.

Do check GitHub’s page: https://github.com/ricmrodrigues/runasync¬†

Usage:

Task:
Dispatch execution to the UI thread (from within a Task.run or continueWith function callback):
Promise:

Performance:

Using RunAsync: http://jsfiddle.net/v7m5p/13/
Running code synchronously: http://jsfiddle.net/UejYX/3/
Example: