Skip to content

Instantly share code, notes, and snippets.

@oberhamsi
Created August 24, 2012 07:28
Show Gist options
  • Select an option

  • Save oberhamsi/3447098 to your computer and use it in GitHub Desktop.

Select an option

Save oberhamsi/3447098 to your computer and use it in GitHub Desktop.
isolated workers and singletons
/**
* 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