Closed dcsan closed 5 years ago
https://docs.pusher.com/chatkit/reference/server-node#sdk-usage
in specific I'm not sure why I get different behavior for
let p = Rabbit.chatkit.getUserRooms({
id: userId
})
p.then( info => {
debug.info('p.then info', info) // empty array []
})
vs doing it all on one line
Rabbit.chatkit.getUserRooms({
userId: userId
}).then( (res, err) => {
debug.info('userRooms p.res', res) // finally found a magic incantation
})
the returned intermediate object IS a promise so...
So I guess there's some magic going on and I just have to be really careful and write old style callback functions to work with the Pusher node API?
@dcsan I can understand your confusion, because all three of the above should indeed be equivalent!
In fact on closer inspection the problem has nothing to do with how you're waiting for the promise... but with a typo in the parameters. The ones which don't work have id: userId
, and the ones which do have userId: userId
.
We should probably add runtime type checks to avoid errors like this, but in the first two cases you are looking for rooms which the user with ID undefined
is in... which is why you get back an empty list...
Sorry for the delay replying here, the issues on this SDK have been slipping through the net somewhat. Our bad.
What?
I'm using the nodeJS lib, and having problems with promises not seeming to resolve when using async/await syntax
only the final method will work
Suggested improvements
I am getting an empty array
[]
as the result so it is notundefined
... but the array hasn't been populated before the Promise resolves, it seems, when using anything other than an inline.then()
Is there a way to get more expected behavior? According to the node docs, each function should return a Promise, but even using
p.then
I can't get quite what I'm expecting. Perhaps this is related to the Promise itself being resolved, but the data isn't ready internally inside somehow from the socket? Really not clear