Created
August 24, 2012 07:28
-
-
Save oberhamsi/3447098 to your computer and use it in GitHub Desktop.
isolated workers and singletons
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * When you see a `postMessage()` it's clear your passing data into | |
| * a different module space. This fact can be obfuscated if you | |
| * use a Singleton. | |
| * | |
| */ | |
| var {Worker} = require("ringo/worker"); | |
| var Foo = function() { return this;} | |
| var FooFactory = function() { | |
| return (new Foo()); | |
| } | |
| var fooFactory = module.singleton('foo', function() { | |
| return FooFactory; | |
| }); | |
| function onmessage(e) { | |
| print('worker:', fooFactory() instanceof Foo); | |
| } | |
| if (require.main === module) { | |
| var w = new Worker(module.id); | |
| w.postMessage(''); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment