1

use the following code for testing promise( I use BlueBird) and I've one Different question (the code is working)

assume that I want to remove the console.log from every function and I want in the then chain to get the value of return and print it to the console, how should I adopt the code?

 var promise1 = function () { 
   setTimeout(function () { 
   //console.log("ret1") return "ret 1"; },
    1000);
};

var promise2 = function () {
    setTimeout(function () {
       // console.log("ret2")
        return "ret 2";
    }, 2000);
};

var promise3 = function () {
    setTimeout(function () {
        //console.log("ret3");
        return "ret 3";
    }, 1000);
    }

;

Promise.resolve()
    .then(promise1)
    .then(promise2)
    .then(promise3)
  • You can't. That's why we use promises with callbacks in the first place. – Quentin Dec 28 '15 at 10:01
  • @Quentin - what I cant do? to print the console inside then? –  Dec 28 '15 at 10:02
  • Return a value from an asynchronous function. – Quentin Dec 28 '15 at 10:05
  • @Quentin Ok but if I want to just send response from function somehow to next function with the "then" how should I do it? I mean remove the return outside the setTimout and when It finish to return value to the chain –  Dec 28 '15 at 10:09
  • 1
    Err. I'm not sure what you are asking there, but it sounds like you really want an introductory promise tutorial. And that your `promise` functions need to be in the promise itself (or rather in one each) and not in the `then` functions. – Quentin Dec 28 '15 at 10:11

0 Answers0