Skip to content

Replace setImmediate with setTimeout 0#14

Merged
mjwwit merged 1 commit intomjwwit:masterfrom
ericwooley:master
Jul 16, 2023
Merged

Replace setImmediate with setTimeout 0#14
mjwwit merged 1 commit intomjwwit:masterfrom
ericwooley:master

Conversation

@ericwooley
Copy link

There are a few references to setImmediate, https://developer.mozilla.org/en-US/docs/Web/API/Window/setImmediate which was only partially adopted by node, and breaks lots of jsdom things.

I think it's usage leads to lots of downstream headaches for users of the lib. See the google results: https://www.google.com/search?q=jsdom++setImmediate+is+not+defined+site:github.com&client=firefox-b-1-d&sxsrf=AB5stBg2qBNE8pVK3DI98qSnmKt7yqTREg:1689006813782&sa=X&ved=2ahUKEwiGgKLZyISAAxVYie4BHdkhB4IQrQIoBHoECBUQBQ&biw=1479&bih=1010&dpr=2#ip=1

This obviously isn't the only lib that uses setImmediate, but it's a big one that I've had to work around on a few projects now.

This PR replaces the use of setImmediate with setTimeout(() => {...}, 0), which is functionally very similar. https://nodejs.dev/en/learn/understanding-setimmediate/

For the purposes of this library, I don't see any reason to use setImmediate over setTimeout.

@ericwooley ericwooley marked this pull request as draft July 10, 2023 16:50
@ericwooley
Copy link
Author

Converted to draft, because appearently my editor decided to add some formatting

@ericwooley ericwooley marked this pull request as ready for review July 10, 2023 16:52
@mjwwit
Copy link
Owner

mjwwit commented Jul 12, 2023

Thanks for this! I'll have a look at it later this week.

Copy link
Owner

@mjwwit mjwwit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!

@mjwwit mjwwit merged commit b01f69a into mjwwit:master Jul 16, 2023
@mjwwit
Copy link
Owner

mjwwit commented Jul 16, 2023

I've just released version 2.1.1 on npm which includes your fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants