Skip to content

Commit

Permalink
* Change -v to --vm and document its usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
audreyt committed Dec 26, 2012
1 parent 9d3572f commit 1ea204f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
9 changes: 9 additions & 0 deletions README.mkdn
@@ -1,5 +1,8 @@
# EtherCalc

* Introduction:
* English: https://gist.github.com/3978463
* 中文版: https://gist.github.com/3985324
* Language: [LiveScript](http://livescript.net/)
* Runtime: [Node.js](http://nodejs.org/) (0.8+ preferred; compatible with 0.4)
* Services: [Redis](http://redis.io) (2.4+; fall-back to on-disk JSON storage if not present)
Expand Down Expand Up @@ -60,6 +63,12 @@ Useful when running under an URL rewriter.

Offers read-write vs. read-only modes. See issues [#1](https://github.com/audreyt/ethercalc/issues/1) and [#4](https://github.com/audreyt/ethercalc/issues/4) for details on setting this up.

### Disable server-side WebWorkers: `--vm`

Runs a single-thread background loop with `vm.createContext` instead of `webworker-threads`.

Useful for running custom functions in server side that requires full VM access.

# Licensing

### Common Public Attribution License (Socialtext Inc.)
Expand Down
2 changes: 1 addition & 1 deletion app.js
Expand Up @@ -15,7 +15,7 @@ This work is published from Taiwan.
};
argv = (function(){
try {
return require('optimist').argv;
return require('optimist').boolean(['vm', 'polling']).argv;
} catch (e$) {}
}()) || {};
json = (function(){
Expand Down
25 changes: 14 additions & 11 deletions sc.js
@@ -1,23 +1,26 @@
(function(){
var vm, fs, path, bootSC, Worker, e, wt;
var vm, fs, path, bootSC, argv, Worker, e;
vm = require('vm');
fs = require('fs');
argv = require('optimist').argv;
path = require('path');
bootSC = fs.readFileSync(path.dirname(fs.realpathSync(__filename)) + "/SocialCalcModule.js", 'utf8');
global.SC == null && (global.SC = {});
argv = (function(){
try {
return require('optimist').boolean(['vm', 'polling']).argv;
} catch (e$) {}
}()) || {};
console.log(argv);
Worker = (function(){
try {
wt = require('webworker-threads').Worker;
} catch (e$) {
wt=null;
if (argv.vm) {
throw 'vm';
}
if (wt!=null && argv.v != true) {
console.log("starting backend using webworker-threads");
return wt;
} else {
//e = e$;
console.log("starting backend using vm.CreateContext");
console.log("Starting backend using webworker-threads");
return require('webworker-threads').Worker;
} catch (e$) {
e = e$;
console.log("Falling back to vm.CreateContext backend");
return (function(){
var prototype = constructor.prototype;
function constructor(code){
Expand Down
2 changes: 1 addition & 1 deletion src/app.ls
Expand Up @@ -10,7 +10,7 @@ This work is published from Taiwan.
*/

slurp = -> require \fs .readFileSync it, \utf8
argv = (try require \optimist .argv) || {}
argv = (try require \optimist .boolean <[ vm polling ]> .argv) || {}
json = try JSON.parse slurp \/home/dotcloud/environment.json
port = Number(argv.port or json?PORT_NODEJS or process.env.PORT or process.env.VCAP_APP_PORT or process.env.OPENSHIFT_INTERNAL_PORT) or 8000
host = argv.host or process.env.VCAP_APP_HOST or process.env.OPENSHIFT_INTERNAL_IP or \0.0.0.0
Expand Down
6 changes: 5 additions & 1 deletion src/sc.ls
Expand Up @@ -5,13 +5,17 @@ bootSC = fs.readFileSync "#{
path.dirname fs.realpathSync __filename
}/SocialCalcModule.js" \utf8
global.SC ?= {}
argv = (try require \optimist .boolean <[ vm polling ]> .argv) || {}
console.log argv

##################################
### WebWorker Threads Fallback ###
##################################
Worker = try
throw \vm if argv.vm
console.log "Starting backend using webworker-threads"
(require \webworker-threads).Worker
catch => class => (code) ->
catch => console.log "Falling back to vm.CreateContext backend"; class => (code) ->
vm = require \vm
cxt = { console, self: { onmessage: -> } }
cxt.window =
Expand Down

0 comments on commit 1ea204f

Please sign in to comment.