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

Modify Promise check, Closes #20 #21

Merged
merged 3 commits into from
Jan 14, 2020
Merged

Conversation

aulisius
Copy link
Contributor

@aulisius aulisius commented Oct 2, 2019

Based on discussion in #20 and googling around, I found this

https://stackoverflow.com/questions/27746304/how-do-i-tell-if-an-object-is-a-promise#27746324

It seems checking for the existence of a then on the prototype/instance is the most consistent solution.

I'm still thinking if there is a way to improve on this.

@andyfleming @joepie91 Any thoughts?

@coveralls
Copy link

coveralls commented Oct 2, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling 2efc2f7 on aulisius:patch-1 into 078528e on andyfleming:master.

@joepie91
Copy link

joepie91 commented Oct 2, 2019

LGTM :)

@bobvanmanen
Copy link

Another use case for this is when async-listener is used. It overrides the global Promise into a WrappedPromise. If the interval function is an async function, the check will fail.

I wonder though, wouldn't it be better to just use this to ensure the returned value is always a Promise:

const returnVal = Promise.resolve(func(currentIteration, stop))

@andyfleming
Copy link
Owner

@bobvanmanen — I'm not sure about long-term, but initially I'm hesitant to make the assumption that non-promise values should just be resolved.

@andyfleming
Copy link
Owner

Thanks for your contribution @aulisius!

@andyfleming andyfleming merged commit f19a69f into andyfleming:master Jan 14, 2020
@aulisius aulisius deleted the patch-1 branch January 18, 2020 01:07
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.

None yet

5 participants