可以在 Javascript Promise 中调用调试器吗?
Can debugger be called in a Javascript Promises?
我正在尝试使用我在 github 上找到的库,但无法调试代码未触发的原因。
//slackTypeForm.js
var Promise = require('bluebird'),
PromiseObject = require('promise-object')(Promise),
request = require('request'),
_ = require('lodash'),
Cubby = require('Cubby');
Promise.promisifyAll(request);
var SlackAutoInviter = PromiseObject.create({
initialize: function ($config) {
this._typeformUID = $config.typeformUID;
this._typeformKey = $config.typeformKey;
this._typeformEmailField = $config.typeformEmailField;
this._typeformFirstNameField = $config.typeformFirstNameField;
this._typeformLastNameField = $config.typeformLastNameField;
this._slackName = $config.slackName;
this._slackToken = $config.slackToken;
this._dataFile = $config.dataFile;
this._cubby = new Cubby({file: this._dataFile});
this._cubby.set('form-id-since', this._cubby.get('form-id-since') || 1);
},
inviteAll: function ($deferred) {
//调试器没有命中这里
调试器;
var typeFormResponse = _.first(request.getAsync({url: 'https://api.typeform.com/v0/form/' + this._typeformUID + '?key=' + this._typeformKey + '&completed=true&since=' + this._cubby.get('form-id-since') + '&limit=1000', json: true}));
Promise.map(typeFormResponse.body.responses, this._inviteUser, {concurrency: 5});
this._cubby.set('form-id-since', Math.floor(Date.now() / 1000));
$deferred.resolve();
},
_inviteUser: function ($deferred, form) {
var inviteResponse = _.first(request.postAsync({
url: 'https://' + this._slackName + '.slack.com/api/users.admin.invite',
form: {
email: form.answers[this._typeformEmailField],
first_name: form.answers[this._typeformFirstNameField],
last_name: form.answers[this._typeformLastNameField],
token: this._slackToken,
set_active: 'true'
},
json: true
}));
console.log('[INVITE] ' + form.answers[this._typeformFirstNameField] + ' ' + form.answers[this._typeformLastNameField] + ' <' + form.answers[this._typeformEmailField] + '>');
$deferred.resolve(inviteResponse.body);
}
});
module.exports = SlackAutoInviter;
// 是否有任何关于如何调试此承诺的信息?
// package.json
{
"name": "slack-typeform-inviter",
"version": "0.0.2",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Chad Scira",
"license": "ISC",
"dependencies": {
"bluebird": "^2.3.10",
"cubby": "0.0.3",
"harmony": "0.0.1",
"lodash": "^2.4.1",
"promise-object": "^0.1.5",
"request": "^2.47.0"
}
}
我正在使用 console.log(code);
它工作正常。
我还没有得到明确的答案,但我的假设是它与延迟的承诺有关,所以 console.log 是。
*更新并回答.
代码原来是节点 0。11.x 它使用不同的语法和承诺。我已经在模块 githubg 页面上提交了一个 pull-request,其中包含有关如何使用 nvm 升级到不稳定版本的节点以使用此代码的说明。
npm install -g nvm
nvm install v0.11.14
然后我就可以随心所欲地调试代码了。
我正在尝试使用我在 github 上找到的库,但无法调试代码未触发的原因。
//slackTypeForm.js
var Promise = require('bluebird'),
PromiseObject = require('promise-object')(Promise),
request = require('request'),
_ = require('lodash'),
Cubby = require('Cubby');
Promise.promisifyAll(request);
var SlackAutoInviter = PromiseObject.create({
initialize: function ($config) {
this._typeformUID = $config.typeformUID;
this._typeformKey = $config.typeformKey;
this._typeformEmailField = $config.typeformEmailField;
this._typeformFirstNameField = $config.typeformFirstNameField;
this._typeformLastNameField = $config.typeformLastNameField;
this._slackName = $config.slackName;
this._slackToken = $config.slackToken;
this._dataFile = $config.dataFile;
this._cubby = new Cubby({file: this._dataFile});
this._cubby.set('form-id-since', this._cubby.get('form-id-since') || 1);
},
inviteAll: function ($deferred) {
//调试器没有命中这里 调试器;
var typeFormResponse = _.first(request.getAsync({url: 'https://api.typeform.com/v0/form/' + this._typeformUID + '?key=' + this._typeformKey + '&completed=true&since=' + this._cubby.get('form-id-since') + '&limit=1000', json: true}));
Promise.map(typeFormResponse.body.responses, this._inviteUser, {concurrency: 5});
this._cubby.set('form-id-since', Math.floor(Date.now() / 1000));
$deferred.resolve();
},
_inviteUser: function ($deferred, form) {
var inviteResponse = _.first(request.postAsync({
url: 'https://' + this._slackName + '.slack.com/api/users.admin.invite',
form: {
email: form.answers[this._typeformEmailField],
first_name: form.answers[this._typeformFirstNameField],
last_name: form.answers[this._typeformLastNameField],
token: this._slackToken,
set_active: 'true'
},
json: true
}));
console.log('[INVITE] ' + form.answers[this._typeformFirstNameField] + ' ' + form.answers[this._typeformLastNameField] + ' <' + form.answers[this._typeformEmailField] + '>');
$deferred.resolve(inviteResponse.body);
}
});
module.exports = SlackAutoInviter;
// 是否有任何关于如何调试此承诺的信息?
// package.json
{
"name": "slack-typeform-inviter",
"version": "0.0.2",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Chad Scira",
"license": "ISC",
"dependencies": {
"bluebird": "^2.3.10",
"cubby": "0.0.3",
"harmony": "0.0.1",
"lodash": "^2.4.1",
"promise-object": "^0.1.5",
"request": "^2.47.0"
}
}
我正在使用 console.log(code);
它工作正常。
我还没有得到明确的答案,但我的假设是它与延迟的承诺有关,所以 console.log 是。
*更新并回答.
代码原来是节点 0。11.x 它使用不同的语法和承诺。我已经在模块 githubg 页面上提交了一个 pull-request,其中包含有关如何使用 nvm 升级到不稳定版本的节点以使用此代码的说明。
npm install -g nvm
nvm install v0.11.14
然后我就可以随心所欲地调试代码了。