AngularJS primitive bindings for thread.js
The most simple and funny multithreading ever, with Angular feelings
For more information about thread.js, please see library the documentation, usage examples and be aware about threads limitations
It works with Angular >= 1.0
Via Bower
bower install angular-thread
Via Component
component install h2non/angular-thread
Or loading the script remotely
<script src="//cdn.rawgit.com/h2non/angular-thread/0.1.3/angular-thread.js"></script>
- Chrome >= 5
- Firefox >= 3
- Safari >= 5
- Opera >= 12
- IE >= 9 (IE8 is not officially supported, but it may work)
- PhantomJS >= 1.7
- SlimerJS >= 0.8
Load the module as dependency of your application
var app = angular.module('app', ['ngThread'])
Main service to creating threads.
It's an injectable shortcut to thread.js
public API
app.factory('CoolService', function ($thread) {
var users = ['John', 'Michael', 'Jessica', 'Tom']
var thread = $thread({
env: { search: 'Tom' },
require: 'http://cdn.rawgit.com/h2non/hu/0.1.1/hu.js'
})
thread.run(function (users) {
return hu.filter(users, function (user) {
return user === env.search
})
}, [ users ]).then(function (users) {
console.log(users) // -> ['Tom']
})
})
Shortcut service to run task in a new thread or custom thread. See the original API method documentation
Running task in a new thread (created transparently). The thread will be killed after the task finished with success or fail state
app.factory('CoolService', function ($threadRun) {
$threadRun(intensiveTask, /* { bind context }, [ task arguments ] */)
.then(function (result) {
// ...
}, function (err) {
// ...
})
})
Reusing an existent pre-configured thread.
app.factory('CoolService', function ($threadRun, $thread) {
var thread = $thread({
env: { timeout: 10 },
require: 'http://cdn.rawgit.com/h2non/hu/0.1.1/hu.js'
})
// define the thread to reuse instead of creating a new one
$threadRun.thread = thread
$threadRun(intensiveTask).then(function (result) {
// ...
}, function (err) {
// ...
})
})
Built-in service to create pool of threads. See the original API method documentation
app.factory('CoolService', function ($threadPool) {
var pool = $threadPool(10)
pool.run(intensiveTask).then(function (result) {
// ...
}, function (err) {
// ...
})
})
Useful helper service to create containers to store and manage thread pools that you could use in your application
It supports basic CRUD operations
app.factory('CoolService', function ($threadStore, $thread) {
var thread = $thread()
// adding
$threadStore.push(thread)
// getting
$threadStore.get() // -> [ Thread ]
// checking
$threadStore.has(thread) // -> true
// removing
$threadStore.remove(thread)
// flushing
$threadStore.flush()
// counting
$threadStore.total() // -> 0
})
Add a new thread to the container
Get all the container threads
Remove a given stored thread in the container
Empty all the container store
Return the total number of threads stored
Return true
if the given thread is already stored in the container
Wanna help? Cool! It will be appreciated :)
You must add new test cases for any new feature or refactor you do, always following the same design/code patterns that already exist
Only node.js is required for development
Clone the repository
$ git clone https://github.com/h2non/angular-thread.git && cd angular-thread
Install dependencies
$ npm install
$ bower install
Generate browser bundle source
$ make browser
Run tests
$ make test
MIT © Tomas Aparicio