« first day (2139 days earlier)      last day (2810 days later) » 

10:00 PM
To show that it's a promise and when it resolves to show its value (and still say it was a promise)
 
@BenjaminGruenbaum It will show something, when it resolves or timeouts
 
Right, but in the meantime you can just show it's a promise
 
will it show, eventually? "I currently have a deadlock somewhere" - You
 
Jay
how can I get the filename and the path of the file in two variables? sample.com/images/image.png
 
That's an interesting topic of it self, but my main point was that objects impl. then doesn't imply an instance of promise.
 
10:02 PM
split on the last index of /
 
Jay
i can get the file name by doing replace(/^.*[\\\/]/, '')
 
@Jay if node, see nodejs.org/api/path.html (the basename function)
 
@Oleander only because you did something super strange to promise objects by implementing your own thenables that violate what every other thenable does - much like passing a {{toString() { throw Error(); }} does.
 
@Luggage I assumed client :/
 
@Luggage I've a couple of 1k function calls (the state is long lived), without the promises. With, maybe the double. I would like to remove them.
 
10:03 PM
@Luggage he probably wants the url module though, and to check the .host?
Oh, the file name, nevermind.
 
Jay
@rlemon how would I do this? lastIndexOf('/')+1
how would that be written?
 
const [path,name] = str.slice(str.lastIndexOf('/'));
maybe
 
@BenjaminGruenbaum "strange" is a relative term. The question isn't. Your answer gave the illusion that what's suggested will solve the problem, but it only partially does this.
 
Jay
and that returns an array?
 
ahh no not that easy.
 
10:07 PM
I'm happy if something like "one possible way of increasing the odds of ... is to ..."
 
sorry I'm only half here
 
@Oleander I gave three answers, and I still don't understand your use case at all since I think passing objects which have a function then that happens to behave differently than anything in the wild and happens to abuse the promise resolution rules in order to "pause" execution is abusive.
 
His answer is spot on until you throw in non-promises with .then() (rare) and using some proxy contraption to fondle promises.
 
was added to the answer.
 
You can probe tons of things - but then is the only one that gives you an answer.
 
10:07 PM
@Jay look up string.slice and lastIndexOf on MDN, you can put together something from that
 
Something can be a jQuery promise - that won't have catch or resolve, or an angular promise that won't be instanceof Promise.
 
Jay
@rlemon k thanks man
 
The only common ground is the Promises/A+ spec and that only addresses then.
 
@BenjaminGruenbaum My use case isn't really interesting here. It's where ever the provided answer, answers the question. It doesn't, as my first comment shows. Using your subjective view, i.e I can't recall this failing' would be limited by your ability to foresee every possible impl, which is by def. an impossible task
 
@Oleander it's the exact same thing as with valueOf and toString and lots of other behavioral interfaces in the language - if it has a .length property Array methods will iterate it - if it has a Symbol.iterator for... of will iterate it - and you can break the expectations of each and every one of those but in practice no one does.
You can redefine Array methods or delete them or break expectations in a million other ways.
What do you do for logging objects? You toString or stringify them? (by writing them somewhere that expects a string?)
!!> Object.create(null) + " Hello!"
 
10:13 PM
@BenjaminGruenbaum "TypeError: can't convert Object.create(...) to primitive type"
 
!!> 5 + ({valueOf: () => 10})
 
@BenjaminGruenbaum 15
 
!!> 5 + {valueOf: () => { throw "LOL!"; }}
 
@BenjaminGruenbaum "LOL!"
 
don't laugh, but I never encountered or knew of valueOf().
 
10:15 PM
@BenjaminGruenbaum Here's is a summery of the problem. en.wikipedia.org/wiki/Affirming_the_consequent
 
!!> " " + {toString: () => {throw "up"}}
 
@BenjaminGruenbaum "up"
 
If P, then Q. Q. Then P.
 
@Oleander the fact something is possible in a language doesn't mean that people will do it. This is true all the time.
@Oleander Also, watch the attitude.
 
It's not a logical fallacy, it's the definition in the spec.
 
10:16 PM
^
 
@BenjaminGruenbaum Sorry, didn't mean to be rude.
 
In fact, in both the userland and the language spec.
 
JS doesn't have interfaces or other ways of this (well, symbols, kinda), so this is all you get.
 
That's the problem.
 
You can do the same thing with symbols.
 
10:17 PM
P: X is a Promise.
 
@Oleander it's not the problem and it's the case in every language.
 
Q: X has a then method.
Q: Y has a then method.
So; Y must be a Promise
 
well.. in c# (and probably java?) you could have explicitly implemented interfaces, so you could re-use .then() with no conflicts.
 
That's false
 
In haskell, if you implement a typeclass it's up to you to make sure you don't violate any invariants it defines. You can implement a monad with a bind that makes no sense for monads and violates the constraint. You can define a .add method on a collection in Java that shuts down your computer. You can define a increment(int& i) method in C++ that always zeros the integer.
@Luggage C# actually does like JS in this case, it checks for the presence of a property called GetAwaiter on the object - so if you have your own non-awaitable that just happens to implement GetAwaiter well...
Just because there are esoteric edge cases doesn't mean you have to pick an inferior design.
 
10:19 PM
I was jsut talking about interfaces in general, not any existing promise-like objects.
 
@BenjaminGruenbaum Could you show me why my statement wasn't true?
 
@Oleander well, if you want to do it like that: en.wikipedia.org/wiki/Straw_man
 
// c# explicit interface implementation
pubic class MyClass : IPromise
{
    Object IPromise.Then(Func resolve, Func reject) {
    }

    Object Then() { //another unrelated .then() method
    }
}
 
@Oleander It's -> The language defines thenables as having a then method, Y has a then method, then in terms of the language Y is a promise.
 
@BenjaminGruenbaum How do you mean that the wikipedia articles applies to this?
 
10:21 PM
@Oleander I never said: X has a then method, Y has a then method, then Y must be a promise. Never.
 
Aha, that's nice. Thanks!
 
I said "the language defined promises and thenables as things that have a then method, Y has a then method, Y is a promise or other form of thenable"
 
"A promise OR something else" is what I was refering to in my original post.
The OP is asking to determine a promise, the above states that it doesn't
 
That "something else" is a promise in every way in the eyes of the promise methods the language defines though.
 
I'm not even sure what is being argued anymore. We all agree it's slightly ambiguous and there is a possibility of a false positive.
 
10:24 PM
I just showed you in all the specs - it is literally only checked that the object has a then. That's why your abuse even works in the first place.
 
That set includes all objects having a then method, that is, a super set of a all existing promises.
 
Right, but that's not different from the tens if not hundreds of other places the language checks for behavioral things and not types.
Array.prototype.map.call(document.querySelectorAll("*"), x=> console.log(x)); // that's why this code works
 
@BenjaminGruenbaum Aha, so I think I know what the problem is.
 
that you are trying to outsmart yourself?
 
10:28 PM
I'm asking to test wherever an object behaves like a Promise according any spec (i.e the offical one). My inital quess would be that the OP was asking for the same thing. If this isn't the case, then I'm totally fine with the current answer.
@Luggage Care to explain how?
 
Nope.
 
so...
10
A: Testing if a method returns an Promise

Florian MargaineTesting if an object is a promise is simple: return !!obj.then && typeof obj.then === 'function'; That's it. If an object has the then method, it's a promise. It looks like angular's $q doesn't have anything to differentiate it from other kind of promises.

 
guys please help
any idea what happened ?
 
it is freezed for some minutes
 
10:31 PM
and really, being a "thennable" is all that really matters.
 
@FlorianMargaine A simple proof of the op. would be x = {then: function() {}}
 
@gtzinos a 45mb commit is pretty big. did you check in compiled output?
 
@Oleander yes, that counts as a promise according to the spec
next question
 
@FlorianMargaine I tried reading the spec liked to by @BenjaminGruenbaum but I couldn't find anything that would imply that. Could you maybe show me where?
*linked
 
@Oleander my answer still says how to test it according to the spec - it doesn't actually say you shouldn't - I'm just telling you my opinion here.
 
10:33 PM
@Luggage it is 300mb
 
Sounds like you are abusing git.
unless that's the linux kernel
 
@BenjaminGruenbaum In that case I'm totally fine with it
 
but i used git ignore
and now it 45mb
 
@Luggage linux kernel doesn't have 45MB commits :)
 
initial commit.
 
@gtzinos what kind of project and what is in your .gitignore?
 
eclipse
java
 
@gtzinos If you're cloning something, you might want to git clone --depth 1
 
i try to reupload an open source project
 
10:35 PM
@Luggage fair, git came fairly late
@Zirak hi hun
 
@BenjaminGruenbaum "under the assumption that x behaves at least somewhat like a promise". That would imply that that it has to be a promise before doing the actual testing?
 
right.. the export from.. bitkeeper?
bitlocker?
no.. that's windows disk encryption.. bitkeeper, i think
 
If you're pushing it's time to check that you're not pushing something you didn't want to (maybe compiled stuff like jars)
 
@Oleander read the actual procedure - what it does is precisely explained there. The spec assumes that if it has a then it behaves like a promise.
 
@FlorianMargaine Ahoy darlin'
 
10:37 PM
@Luggage my memory says bitkeeper too
@Zirak how's life
 
Lifey. I was about to go a sleepin' but then saw duck pictures.
 
guys
its normal of git push ?
 
@BenjaminGruenbaum Yes. " If x is a thenable, it attempts to make promise adopt the state of x, under the assumption that x behaves at least somewhat like a promise. Otherwise, it fulfills promise with the value x.".
 
don't show me a progress bar
 
@Oleander read the actual algorithm...
 
10:38 PM
How're you?
Also, a praying mantis just attacked me
 
@BenjaminGruenbaum So; if "x" is thenable and behaves like a promise, it's a promise.
 
@Oleander yes.
 
@Zirak fine, thank you
@Zirak that's so cool
 
@Zirak why?
Did you put on a horse mask?
 
@BenjaminGruenbaum his foreign policy
 
10:38 PM
@BenjaminGruenbaum I dunno, maybe it's because of my awesome facial hair
 
@BenjaminGruenbaum So if you can show x is "thenable" you also need to show "x" is behaves like a promise.
 
@Zirak Oh yeah dude you gotta shave.
 
Or my Olympic medal in Mediocrity
 
@Oleander no, the spec just assumes it does - read the actual spec.
I sent you a direct link to that clause
Look at 2.3.3
 
@BenjaminGruenbaum Is there anything wrong with what I quotes?
*quoted
 
10:40 PM
It's out of context
 
Aha, sorry. 2.3.3
Just a sec
 
@Oleander No, you just extrapolated more meaning than what's there
 
@BenjaminGruenbaum would you tell a man to cut his balls?
 
Your quote says "If x is thenable, we treat it like a promise. If it's not thenable, we make it one."
@FlorianMargaine ...you wouldn't download a car
 
user1596138
@Zirak Ur mom's thenable
2
 
user1596138
10:41 PM
I had a meme for you the other day
 
user1596138
Hold on
 
@Jhawins I told you that in confidence!
 
@BenjaminGruenbaum This is interesting, give me 10 min :)
 
user1596138
 
user1596138
@Zirak and @BenjaminGruenbaum climbing walls
 
user1596138
10:42 PM
Because you guys had that secret goat room.
 
:(
good ol' goats
 
@Jhawins Whatever floats levitates your goat
Anyway, either the praying mantis eats me in my sleep, or it somehow died and ants will start feasting on its body before moving to me. Either way, outlook not good.
 
@BenjaminGruenbaum I'm not sure I understand the abstract details. In the case of '[[Resolve]](promise, x)', What's 'x' and what's 'promise' in for example A.then(B)?
 
@Zirak or it may be that the praying mantis will attract a beautiful woman in your bed.
 
@BenjaminGruenbaum Promise.resolve(x)?
 
10:49 PM
or a beautiful man, whatever levitates your boat.
 
or both
 
@Oleander whenever you return from the then, the value is 'as if' it was passed to Promise.resolve
If it has a then then call its then and subscribe to its result.
 
@BenjaminGruenbaum Hehe, that's a mind twister. I need to digest that for a while.
@BenjaminGruenbaum To make it more relatble (for me) in the case of 'obj.then' what would be 'promise' and 'x'?
 
@Oleander yup, and so on and so on - there are around 2000 tests to make sure this procedure works accurately - for example it only calls then once in case it is a getter and deals with what happens when it throws, or when then is added to Number.prototype.
@Oleander promise is this promise, which had a then fulfillment handler - and x is the result of invoking it with the value of promise.
 
@BenjaminGruenbaum So the 'promise' is 'obj'?
 
10:53 PM
Yes
And x is the result of calling the then handler (the return value). It might be a promise itself which is why [resolve] is called again.
!!> Promise.resolve(Promise.resolve(Promise.resolve(Promise.resolve(Promise.resolve(‌​5))))).then(x => console.log(x))
 
@BenjaminGruenbaum "SyntaxError: missing ) after argument list"
 
Promises unwrap recursively.
 
@BenjaminGruenbaum "SyntaxError: missing ; before statement"
@BenjaminGruenbaum "undefined" Logged: 5
 
@BenjaminGruenbaum So 'promise' don't define the type Promise, they already assumed it's a promise?
 
@Oleander yes, because [resolve] was called on it.
 
10:55 PM
Hmm, that's a strange sentence
I'll fix it
(my sentence)
 
Just read the spec :P
If you want to really understand it well, implement a library and run it against the tests.
This is old but maybe it'll help modernjavascript.blogspot.co.il/2013/08/… @Oleander
 
@BenjaminGruenbaum So you would need to show that 'promise' is a promise according to the spec before you can use it as a reference?
 
This spec describes two things - your library whose promises are called promises (this can be bluebird) and external objects you are consuming that might come from your library and might not (this can be native promises).
It describes how your implementations' promise then should behave in how it assimilates other implementations.
 
@BenjaminGruenbaum To summerize; The spec defines how to handle 'x' given a promise 'promise'. Is that correct?
The part you linked to that is
 
right, where you want to detect if x is a promise.
 
11:01 PM
I'm not refering to the entire spec
 
And the only criteria is that it has a "then" property.
 
@BenjaminGruenbaum This statement "If retrieving the property x.then [...] reject promise [...]". The seem to have defined 'promise' already. In the case of 'obj.then' 'promise' doesn't exist. It looks like they have defined a context != 'obj.then', no?
 
9 mins ago, by Benjamin Gruenbaum
This spec describes two things - your library whose promises are called promises (this can be bluebird) and external objects you are consuming that might come from your library and might not (this can be native promises).
 
@BenjaminGruenbaum You said 2.3.3 was relevant, right? Your quote might be relevant as a whole, but I think it's easier if you take one step at the time to minimize the confusion. Is it okay if we focus on 2.3.3?
Or are you refering to 'the spec' as 2.3.3?
 
In this case yes but also as a whole.
 
11:12 PM
@BenjaminGruenbaum Awesome. Feel free to pause if I'm talking up your time. I'm doing this to learn, not to bash your answer. Not sure if that's clear :)
What I dont understand is the first sentence.
 
I don't actually care if you bash my answer, points are meaningless in SO and I have too many anyway I'm cool with the discussion.
 
"[...] a promise and a value [...]"
 
Right, and the value might also be a promise.
 
There is already an assumption that something somewhere is a promise in the environment we're using. I can come up with an example that doesn't have a promise, where I still need to test .then. Wouldn't that make the 2.3.3 non applicable?
@BenjaminGruenbaum Good to hear!
 
@Oleander it would still be applicable, you now have a promise implemetation P and you did P.resolve().then(() => return fn())` where fn returns an object with a then, 2.3.3 means that you should treat it as a promise and attach a then handler to it and assimilate its value.
 
11:17 PM
Hmm, okay
Just to make it a bit more formal
The first sentence says; "The promise resolution procedure is an abstract operation taking as input a promise and a value"
So 2.3 is denoted to an environment where we have 'promise' and 'x'.
 
Right, and you got there by doing something like returning x from a then handler.
 
Even more: 2.3 is applicable iff we've X and Y.
@BenjaminGruenbaum Is that correct?
 
I didn't define them, but sure. It makes sense for one promise implementation to detect if something is by another promise implementation
Just like you'd want to detect if something is a promise in your code - not being the promise library itself.
 
By removing X or Y, 2.3 wouldn't be applicable anymore, right?
 
resolve wouldn't be interesting without it.
 
11:21 PM
Aha, that might be the thing
@BenjaminGruenbaum But it still wouldn't be applicable without X and Y, right?
 
You didn't define X or Y
 
@BenjaminGruenbaum Yes. a post posts up "So 2.3 is denoted to an environment where we have 'promise' and 'x'.
"
 
Right, so use promise and x, not X and Y
 
I'm trying to generalize as it makes it easier to talk about
@BenjaminGruenbaum Hehe, you didn't answer my question :)
Yes or no is fine
 
I didn't understand your question.
 
11:27 PM
ok.. i ordered, waited for and ate dinner. Are we still talking about this?
 
Where did you loose me?
@Luggage Yepp :) The Socratic dialogue is an awesome way to learn
@BenjaminGruenbaum You agreed with me till 'By removing X or Y, 2.3 wouldn't be applicable anymore, right?
'
So, by removing X or Y 2.3 would be invalid. X here is defined as a promise (accordning to the spec). There isn't any promise. There might not be a promise library at all. Thus proving that 2.3 can't be used
This invalidates the SO answer, which was my initial goal.
 
Nono, you already know promise is a promise.
You want to see if x is, see where [resolve] is called.
 
@BenjaminGruenbaum How do I know that? Could you give me an example?
 
Look at where [resolve] is actually called.
 
@BenjaminGruenbaum Is there an oneliner to summerize it?
 
11:35 PM
Yes, you already know it's a promise since you got there by doing it.then and this is the spec for how you should implement it [resolve] is about other promises.
 
@BenjaminGruenbaum If I know it's a promise why would I test it?
 
@Oleander you're not testing promise you're testing x
 
@BenjaminGruenbaum Could you give me an example?
Promise.resolve(x) ?
Is that the one?
 
.resolve is not spec'd there - but yes.
 
@BenjaminGruenbaum What would be the next step?
Wait for it to resolve, and if it does; it's a promise?
 
11:39 PM
If it has a then- it's a promise so track its then, otherwise fulfill with it as the value.
 
Could you be more percise? I dont really know what 'it' is here. Is it the result of 'Promise.resolve(x)'?
 
Hmm, I just showed that the existence of 'x.then' isn't enough to dermine an instance of Promise. Did I miss anything ?
 
That's the point, if it has x.then it considers it a promise.
 
Yes. Everything. Then is the only function that matters.
 
11:44 PM
That's literally what the spec is saying.
> If then is a function, call it with x as this, first argument resolvePromise, and second argument rejectPromise
 
@BenjaminGruenbaum We only have one object 'obj' as far as I know.
 
It's inside an if x is an object...
 
@Luggage That's assumption, not a proof.
 
No. I just read it.
it only mentions 'then' in the spec.
> “promise” is an object or function with a then method whose behavior conforms to this specification.
no speculation, no logical trickery
 
@Luggage Showed a proof of this a couple of posts up. I can explain it again if you want to.
 
11:48 PM
You obviously don't like the answer and are trying REALLY hard to disect the language until it agrees with you.
 
@Luggage I'm not sure you got the whole picture. Have you read my motivation for having this discussion in the first place?
@Luggage The quote you posted already assumes 'promise'.
 
Ohh, I got the picture. You don't like how JS code tests for promises / thenables and you are willing to keep saying it aint so until we agree.
 
@Luggage No, that's not it.
 
The quote I posted is the fisrt line of the spec.
it's defining promises, not assuming
 
@Luggage It assumes the object 'then' exists within already is a promise
 
user5957083
11:52 PM
Hey
 
@ChristopherPeart Welcome to the JavaScript chat! Please review the room rules. Please don't ask if you can ask or if anyone's around; just ask your question, and if anyone's free and interested they'll help.
 
user5957083
So quick question if is processing still considered js?
 
@Oleander it's in the spec under "terminology". They are telling you what they are calling a promise. If you can't get past that, then I can't help.
@ChristopherPeart I don't understand, please rephrase.
 
@Luggage What do you think we're talking about?
That was a sinsear (spelling?) question
 
You are telling me that my quote is an assumption and I am telling you that it's a definition
and you are still not getting it. so please don't talk to me.
 
user5957083
11:54 PM
Wow sorry. Is processing still considered js?
 
I am not as patient as Ben.
And I now think you are trolling.
 
ProcessingJS is JS, processing the language is not.
 
@Luggage I mean what we're trying to solve
or conclude might be more correct phrase
 
@ChristopherPeart Do you mean the library called "processing.js" or just precessing in general?
 
user5957083
The library or processing in general (would like answer for both)
 
11:55 PM
I don't care what you are trying to sovel because i am tired of having every straightforward statement fired back at me with "assumption, no proof, bad logic".
@ChristopherPeart processing.js is written in JS, so yes. The other form is too vague of a question to be meaingful.
 
!!welcome ChristopherPeart
 
@ChristopherPeart Welcome to the JavaScript chat! Please review the room rules. Please don't ask if you can ask or if anyone's around; just ask your question, and if anyone's free and interested they'll help.
 
user5957083
Thanks
 
@Luggage Would that make your posts irrelevant?
 
@Oleander please stop pinging me, I am trying to get out of this conversation.
I don't care anymore.
 
user5957083
11:57 PM
I just lost the game
 
user5957083
Never look at the room rules
 
:)
 
user5957083
ever
 
@Luggage Take a few min to think about why you're feeling this way. Then lookup cognitive dissonance. I'm not trying to be mean. It's just interesting reading material if you want to understand yourself better.
 
user5957083
So is the top stared post.. What kind of card
 
user5957083
11:59 PM
?
 
@ChristopherPeart it's to congratulate you for your butt
 

« first day (2139 days earlier)      last day (2810 days later) »