Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fastTimeout conditional export #5

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion src/fastTimeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;