1

i've learn many about promises with your guides, friends
but a question is created in my mind after learning :

is it true(possible) to build whole project only with promises?
if not: where is more useful than promise?

mo30
  • 89
  • 1
  • 6
  • 1
    no, because the majority of "built-in" node functions don't use Promises ... note: Promises can't work without the notion of a callback either – Jaromanda X Aug 14 '17 at 04:20
  • 1
    A promisified function actually is a plain function that returns a Promise object, and almost all native javascript functions are plain functions, then how it is possible? Callback doesn't mean it will be invoked asynchronously, sometimes it;s just a dependency injection (or IoC) design, e.g., many Array, String methods need a callback function, but they called it synchronously. – tibetty Aug 14 '17 at 04:21
  • 2
    Promises are great for some types of notifications. But, they have a narrowly defined set of requirements for them to be a fit (notify once and only once, must fit into a pending => resolved or pending => rejected model, are not synchronous, etc...). So, I'd say use them for all async operations that fit into the above model, but use EventEmitters or regular callbacks or other publish/subscribe models for other types of notifications. See [When to use Promises vs Callbacks](https://stackoverflow.com/questions/45041462/node-js-when-to-use-promises-vs-callbacks/45046393) for more info. – jfriend00 Aug 14 '17 at 05:11

1 Answers1

1
  1. A promisified function actually is a plain function that returns a Promise object, and almost all native javascript and built-in node.js functions are plain functions, then how it is possible?
  2. Callback function doesn't mean it will be invoked asynchronously, sometimes it's just a dependency injection (or IoC) design, e.g., many Array, String methods need a callback function, but they called it synchronously, while Promise is a asynchronous mechanism.
tibetty
  • 563
  • 2
  • 10