Permalink
Browse files

Added license block

  • Loading branch information...
1 parent 9f53efb commit 353aa11370113c7a70798ef439fdae6297547b31 @Qard committed Apr 1, 2012
Showing with 21 additions and 4 deletions.
  1. +8 −4 index.html
  2. +4 −0 worker.js
  3. +9 −0 workforce.js
View
@@ -4,26 +4,30 @@
<title>Workforce</title>
<script type="text/javascript" src="/workforce.js"></script>
<script type="text/javascript">
+ // Start worker
var worker = new Workforce('worker.js');
+ // Receive pong response to the emitted ping
+ worker.emit('ping');
worker.on('pong', function (e) {
console.log('ping, pong');
});
+ // Pass object in and received modified version
+ worker.emit('foo:bar', { foo: 'bar' });
worker.on('foo:baz', function (e, obj) {
console.log('foo:baz received', obj);
});
+ // Catch the wild events using wildcards
worker.on('wild:*', function (e) {
console.log('wild:* triggered from', e.name);
});
+ // Catch all events with 'o' in them using regex
worker.on(/o/, function (e) {
console.log('/o/ triggered from', e.name);
- })
-
- worker.emit('ping');
- worker.emit('foo:bar', { foo: 'bar' });
+ });
</script>
</head>
<body></body>
View
@@ -1,14 +1,18 @@
+// The workforce lib needs to be imported
importScripts('workforce.js');
+// Respond to ping
self.on('ping', function () {
self.emit('pong');
});
+// Modify object and respond
self.on('foo:bar', function (e, obj) {
obj.foo = 'baz';
self.emit('foo:baz', obj);
});
+// Trigger the wildcard events
self.emit('wild:1');
self.emit('wild:2');
self.emit('wild:3');
View
@@ -1,3 +1,12 @@
+/**
+ * Workforce - Wildcard/regex supported event interface for web workers
+ *
+ * Copyright (c) 2012 Stephen Belanger
+ * Licensed under MIT License
+ *
+ * Worker and normal context parts can easily be extracted
+ * for minification, but both depend on WorkforceEvent.
+ */
function WorkforceEvent (name) {
this.name = name;
}

0 comments on commit 353aa11

Please sign in to comment.