Skip to content
Browse files

* Implement setTimeout in terms of .nextTick.

  Also makes exports.js runnable within a webworker-threads context.
  • Loading branch information...
1 parent 03dc55f commit a0e657575b8faa3038c04090d4f57bbda6cb717b @audreyt committed
Showing with 18 additions and 3 deletions.
  1. +8 −0 exports.js
  2. +6 −2 sc.js
  3. +4 −1 src/sc.ls
View
8 exports.js
@@ -2,6 +2,14 @@ if (typeof global != 'undefined') var window = global;
if (typeof SocialCalc != 'undefined' && typeof module != 'undefined') module.exports = SocialCalc;
if (typeof document == 'undefined') var document = SocialCalc.document = {};
+// Compatibility with webworker-threads
+if (typeof self !== 'undefined' && self.thread) {
+ window.setTimeout = function (cb, ms) {
+ if (ms <= 1) { self.thread.nextTick(cb); }
+ };
+ window.clearTimeout = function () {};
+}
+
// We don't really need a DOM-based presentation layer for embedded SC.
SocialCalc.GetEditorCellElement = function () {};
SocialCalc.ReplaceCell = function () {};
View
8 sc.js
@@ -47,8 +47,12 @@
SocialCalc: null,
ss: null,
window: {
- setTimeout: setTimeout,
- clearTimeout: clearTimeout
+ setTimeout: function(cb, ms){
+ if (ms === 1) {
+ return process.nextTick(cb);
+ }
+ },
+ clearTimeout: function(){}
},
console: console
});
View
5 src/sc.ls
@@ -32,7 +32,10 @@ global.SC ?= {}
SC[room]._doClearCache!
return SC[room]
sandbox = vm.createContext {
- SocialCalc: null, ss: null, window: { setTimeout, clearTimeout }
+ SocialCalc: null, ss: null, window: {
+ setTimeout: (cb, ms) -> process.nextTick cb if ms <= 1
+ clearTimeout: ->
+ }
console
}
vm.runInContext bootSC, sandbox

0 comments on commit a0e6575

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