News for hackers. Stuff that matters.
Re:A one-line package broke `npm create-react-app` by devit on Saturday April 25, 2020 @03:32PM (#22980699)
A function like this should not be something that anyone even thinks of writing or using.

In properly designed languages, values have either a known concrete type, or the interfaces that they have to support are listed, and the compiler checks them.

Even in JavaScript/TypeScript, if you are using this, you or a library you are using are doing it wrong, since you should know whether a value is a promise or not when writing code.

Re:A one-line package broke `npm create-react-app` by city41 on Saturday April 25, 2020 @03:38PM (#22980744)
This function is most likely an artifact of before promises got standardized. One way promises took off and became so ubiquitous is different implementations could interop seamlessly. And the reason for that is a promise was defined as 'an object or function having a then method which returns a promise when called'.

Doesn't excuse the JS ecosystem and JS as a whole, which truly is a mess. But there's a history behind these things.

Re:A one-line package broke `npm create-react-app` by stefan_ on Saturday April 25, 2020 @04:31PM (#22981198)
I think the point of the comment is: you should not be testing for this at all.

If your API works with promises, call .then() on what is handed to you. That's it. Don't make up emergent, untestable behavior on the spot.

Re:A one-line package broke `npm create-react-app` by city41 on Saturday April 25, 2020 @04:37PM (#22981238)
You need to do this test if you are creating a promise implementation. That was my point, there is a reason code like this exists.
Re:A one-line package broke `npm create-react-app` by earthboundkid on Sunday April 26, 2020 @08:07AM (#22986543)
Why would an implementation need to test for it?

ISTM that a framework may need to test for promiseness if it calls promises and functions differently, but it can and should be done as a utility in the framework, not as a separate package.

Re:A one-line package broke `npm create-react-app` by city41 on Sunday April 26, 2020 @10:22AM (#22987341)
I agree with that. I have no idea why it’s in a separate package. But I can say that about many packages :).

It’s possible to just treat everything as a promise by wrapping results in Promise.resolve() but that can have performance implications that some franeworks might want to avoid by only going down the promise route when they have to.

For promise implementations, If the callback to then() returns a promise, the promise implementation detects that and resolves that promise behind the scenes: http://www.mattgreer.org/articles/promises-in-wicked-detail/...