chaining promises with q.js

后端 未结 2 1592
一整个雨季
一整个雨季 2021-02-19 23:32

I\'m trying to understand how promise chaining works. I\'m using q.js. Here\'s what I\'m playing with.

var Q = require(\"q\"); // npm install q

// the functio         


        
2条回答
  •  Happy的楠姐
    2021-02-20 00:29

    I know javascript doesn't have static types, but you need to think about types here.

    Q(1);                             // has type Promise[Int]
    function (n) { return Q(2); }     // has type Int => Promise[Int]
    

    Q.then needs the second.

提交回复
热议问题