diff --git a/README.md b/README.md index 2ca3e6f..ddfbee0 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Alternatively, if you are directly using the library as a browser embed: ## Compatibility -While `fastTimeout` is based on `postMessage`, it automatically falls back to `setImmediate` in environments where that function is defined. Hence, you can transparently use it in Node.js as well. +While `fastTimeout` is based on `postMessage`, it automatically falls back to `setImmediate` in environments where that function is defined. Hence, you can transparently use it in Node.js as well. In environments where neither `postMessage` nor `setImmediate` is defined, it falls back to plain `setTimeout`; you get a performance degradation in that case, but at least your code will still work. ## Reference diff --git a/src/fastTimeout.js b/src/fastTimeout.js index 908e925..6659922 100644 --- a/src/fastTimeout.js +++ b/src/fastTimeout.js @@ -40,5 +40,6 @@ function enable() { } var hasSetImmediate = (typeof setImmediate === 'function'); +var hasPostMessage = (typeof self.postMessage === 'function'); -export default hasSetImmediate ? setImmediate : enable(); +export default hasPostMessage ? enable() : hasSetImmediate ? setImmediate : _.defer;