JavaScript承诺q.timeout问题

时间:2019-05-10 14:45:23

标签: promise

我正在使用q.timeout,请参见下文

        _.each(AppRegistry.apps, function (app, i) {
            if (app.isaProjectFormat()) {
                console.dir(app.typeName);

                Q.timeout(
                    this.generateThemes(app),
                    90 * 1000, // 90 seconds
                    'brand-async-generation-timeout'

我将以上内容包装在_.each周围。不幸的是,在为数组中的每个项目完成generateThemes函数之前,总是会调用then函数。我在正确使用诺言吗?

1 个答案:

答案 0 :(得分:0)

promise.timeout(10000).then(
  function (result) {
    // will be called if the promise resolves normally
    console.log(result);
  },
  function (err) {
    // will be called if the promise is rejected, or the 10 second timeout occurs
    console.log(err);
  }
);

https://github.com/kriskowal/q/wiki/API-Reference#promisetimeoutms-message