7

Switching over to Bluebird from Q, I just want to make sure it's culturally correct: Is there an equivalent to Q.when(someValue); or Q(someValue);?

Is it Promise.resolve(someValue);?

thefourtheye
  • 233,700
  • 52
  • 457
  • 497
asking
  • 1,435
  • 3
  • 13
  • 21
  • This isn't a duplicated question: I'm asking what pattern should be used when you have a value that should be immediately returned, which is dissimilar to the question @gruenbaum you provided as duplicate. Please advise. – asking May 28 '15 at 01:35
  • Answers there do explain how to actually use Bluebird instead of Q. And I haven't used Q much, but you might be correct, i.e. you could use `Promise.resolve(value)` to return a simple resolved promise (which can be `.then(..`) if that's what Q.when does. Also if you post more context, like what you're trying to do someone might tell you how to better use Bluebird instead of finding equivalents, as Bluebird tends to fix a lot of anti-patterns used in other Promise libraries. – laggingreflex May 28 '15 at 02:57
  • Thanks @ laggingreflex, but although answers there may explain how to use Bluebird, the question asked there is "how to create an empty promise" - that's not what I'm asking, so the answers there shouldn't answer my question, and I'm asking "how to create a fulfilled promise in Bluebird" - totally different question, which means I haven't asked a duplicate question. So, can we all stop trolling for points? I just want to have a conversation about code and the culture of an API. – asking May 28 '15 at 05:03
  • Does this help somehow: http://stackoverflow.com/questions/22684643/define-empty-bluebird-promise-like-in-q ? – OddDev May 28 '15 at 10:02
  • Yes, it's the similar question. You're just asking how to use Q which is Q.when (they're the same function) in Bluebird - which is what that question asks. – Benjamin Gruenbaum May 28 '15 at 10:40
  • @asking an empty promise with a value is a fulfilled promise. That's the same thing basically. There is no such thing as "empty" promise, an empty promise is just a fulfilled promise with `undefined` as the fulfillment value - it's the same question. – Benjamin Gruenbaum May 28 '15 at 10:42

1 Answers1

12

Is it Promise.resolve(someValue);?

Yes.

Gabriel L.
  • 1,629
  • 1
  • 17
  • 18