f5io / bonobo-js

A work-monkey to do your dirty business.
38 stars 4 forks source link

Bonobo (v2.1)

A lightweight wrapper for the HTML5 Web Worker API.

Author: Joe Harlow (joe@f5.io)


Bonobo provides a simple wrapper for the HTML5 Web Worker API. It is library agnostic and has no dependencies.

Bonobo allows you to define workers inline, negating the need for seperate JavaScript files.

Version 2.0+


Bonobo v2.0+ adds a completely revised set of methods. Please make sure to read the docs if you wish to start using v2.0+.

Browser Support


Bonobo is built on the Web Worker and Blob APIs. When these are not available it will purely run the task in the main thread by creating a fake worker. This should allow the usage of Bonobo in a Progressive Enhancement environment.

For full capabilities, the following browsers are supported:

Installation


Bonobo can be installed with either npm or bower, by running:

npm install bonobo or bower install bonobo respectively.

Usage


Bonobo can be loaded using CommonJS-style module definitions using browserify, if the package has been installed via npm.

var Bonobo = require('bonobo');

If loaded with a <script> tag, Bonobo can be accessed using either Bonobo or bN on the window object.

From here on out, we will refer to it as Bonobo.

Bonobo has two sets of methods. One relates to methods available in your main JavaScript file/thread, the other relates to methods available from within your worker.

Transferable Objects


Bonobo has built in systems to deal with Transferable Objects intelligently. If the content being transferred between threads can be automatically converted into an ArrayBuffer then it will be transferred as such. This allows for transferring of large Strings, Objects or Arrays to happen quickly and efficiently. Please be aware: This will not allow you to transfer prototype chains or Functions between threads, plain objects only.

Main Thread


Bonobo(reference /* String */)

Calling Bonobo('monkey') creates and returns a new Employee with a reference of 'monkey'. The created Employee can be retrieved at any time using the same method.

The returned Employee has the following methods, which are chainable:

Employee Thread


License


Copyright (C) 2014 Joe Harlow (Fourth of 5 Limited)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.