Skip to content

Commit 7fc0c59

Browse files
author
fresa
committed
Changed the layout of the readme and added some comments.
1 parent d390727 commit 7fc0c59

File tree

1 file changed

+49
-41
lines changed

1 file changed

+49
-41
lines changed

README.md

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,57 +14,65 @@ The returned web worker runs it's own angular context which allows it to resolve
1414
##Installation
1515

1616
install with bower using:
17-
<pre><code>
18-
bower install angular-workers
19-
</pre></code>
17+
18+
bower install angular-workers
2019

2120
##How to use
2221

23-
1. Depend on the WorkerService.
24-
2. Specify the URL to the file containing the angular script by invoking:
22+
* Depend on the WorkerService.
23+
* Specify the URL to the file containing the angular script by invoking:
24+
25+
26+
// The URL must be absolute because of the URL blob specification
27+
WorkerService.setAngularUrl(url)
28+
29+
30+
* OPTIONALLY: Specify how the web worker is to find any dependencies by invoking:
2531

26-
<pre><code>
27-
// The URL must be absolute because of the URL blob specification
28-
WorkerService.setAngularUrl(url)
29-
<pre><code>
3032

31-
3. OPTIONALLY: Specify how the web worker is to find any dependencies by invoking:
33+
// The URL must be absolute because of the URL blob specification
34+
WorkerService.addDependency(serviceName, moduleName, url)
3235

33-
<pre><code>
34-
// The URL must be absolute because of the URL blob specification
35-
WorkerService.addDependency(serviceName, moduleName, url)
36-
</pre></code>
3736

38-
4. Create create a promise of an angularWorker by invoking:
37+
* Create create a promise of an angularWorker by invoking:
38+
3939

40-
<pre><code>
4140
var workerPromise = WorkerService.createAngularWorker(['input', 'output' /*additional optional deps*/,
42-
&nbsp;&nbsp;function(input, output /*additional optional deps*/) {
43-
&nbsp;&nbsp;&nbsp;&nbsp;// This contains the worker body
44-
&nbsp;&nbsp;&nbsp;&nbsp;// The function must be self contained (the function body will be converted to source)
45-
&nbsp;&nbsp;&nbsp;&nbsp;// The input paramter is what will be passed to the worker when it is to be executed, it must be a serializable object
46-
&nbsp;&nbsp;&nbsp;&nbsp;// The output parameter is a promise and is logically what the worker will return to the main thread.
47-
&nbsp;&nbsp;&nbsp;&nbsp;// All communication from the worker to the main thread is performed by resolving, rejecting or notifying the output promise
48-
&nbsp;&nbsp;&nbsp;&nbsp;// We may optionally depend on other angular services. These services can be used just as in the main thread.
49-
&nbsp;&nbsp;}]);
50-
</code></pre>
51-
52-
5. When the workerPromise resolves the worker is initialized with it's own angular context and is ready to use. Like so:
53-
<pre><code>
41+
function(input, output /*additional optional deps*/) {
42+
// This contains the worker body.
43+
// The function must be self contained. The function body will be
44+
// converted to source and passed to the worker.
45+
// The input parameter is what will be passed to the worker when
46+
// it is executed. It must be a serializable object.
47+
// The output parameter is a promise and is what the
48+
// worker will return to the main thread.
49+
// All communication from the worker to the main thread is performed
50+
// by resolving, rejecting or notifying the output promise.
51+
// We may optionally depend on other angular services.
52+
// These services can be used just as in the main thread.
53+
// But be aware that no state changes in the angular services in the
54+
// worker are propagates to the main thread. Workers run in fully isolated
55+
// contexts. All communication must be performed through the output parameter.
56+
}]);
57+
58+
59+
* When the workerPromise resolves the worker is initialized with it's own angular context and is ready to use. Like so:
60+
61+
5462
workerPromise.then(function success(angularWorker) {
55-
&nbsp;&nbsp;&nbsp;&nbsp;//The input must be serializable
56-
&nbsp;&nbsp;&nbsp;&nbsp;return angularWorker.run(inputObject);
57-
&nbsp;&nbsp;}, function error(reason) {
58-
&nbsp;&nbsp;&nbsp;&nbsp;//for some reason the worker failed to initialize
59-
&nbsp;&nbsp;&nbsp;&nbsp;//not all browsers support the HTML5 tech that is required, see below.
60-
&nbsp;&nbsp;}).then(function success(result) {
61-
&nbsp;&nbsp;&nbsp;&nbsp;//handle result
62-
&nbsp;&nbsp;}, function error(reason) {
63-
&nbsp;&nbsp;&nbsp;&nbsp;//handle error
64-
&nbsp;&nbsp;}, function notify(update) {
65-
&nbsp;&nbsp;&nbsp;&nbsp;//handle update
66-
&nbsp;&nbsp;});
67-
</pre></code>
63+
//The input must be serializable
64+
return angularWorker.run(inputObject);
65+
}, function error(reason) {
66+
//for some reason the worker failed to initialize
67+
//not all browsers support the HTML5 tech that is required, see below.
68+
}).then(function success(result) {
69+
//handle result
70+
}, function error(reason) {
71+
//handle error
72+
}, function notify(update) {
73+
//handle update
74+
});
75+
6876

6977
The same initialized worker can be used many times with different input.
7078

0 commit comments

Comments
 (0)