Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

worker sample

  • Loading branch information...
commit 781d71fee6edec13123e6f5edd65638efbc87e26 1 parent d46c822
@cho45 authored
Showing with 33 additions and 0 deletions.
  1. +33 −0 sample.html
View
33 sample.html
@@ -212,6 +212,39 @@ <h1 id="top">JSDeferred Sample</h1>
</div>
<div clsss="section">
+ <h2>Workers</h2>
+ <pre id="worker-code" onclick="eval($(this).text());">
+var queue = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
+var workers = new Array(2);
+var work = function (job) {
+ print('working... ' + job);
+ return wait(3);
+};
+
+for (var i = 0, len = workers.length; i < len; i++) {
+ workers[i] = next(function me () {
+ var job = queue.shift();
+ if (!job) return;
+
+ print("start worker: " + job);
+ return next(function () { return job }).
+ next(work).
+ next(me);
+ }).
+ error(function (e) {
+ alert(e);
+ });
+}
+
+parallel(workers).next(function () {
+ print('all done!');
+});
+
+function print (m) { $("#worker-code").append("\n// "+m) }
+</pre>
+ </div>
+
+ <div clsss="section">
<h2>Divided Loop</h2>
<pre id="loop-code" onclick="eval($(this).text());">
next(function () {

0 comments on commit 781d71f

Please sign in to comment.
Something went wrong with that request. Please try again.