2015-01-11 47 views
1

我正在嘗試使用我在github上找到的庫,並且無法調試代碼未啓動的原因。調試器可以在Javascript Promise中調用嗎?

//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" 
    } 
} 
+0

爲什麼你的函數需要$延期? –

回答

1

我只是用console.log(code);它工作正常。

我還沒有得到明確的答案,但我的假設是它與延遲的承諾有關,所以console.log就是這樣。

*更新和回答

代碼竟然是節點0.11.x,它使用與promise不同的語法。我已經在模塊githubg頁面上提交了一個pull-request,其中包含有關如何使用nvm升級到不穩定版本的節點以使用此代碼的說明。

npm install -g nvm

nvm install v0.11.14

當時我能夠調試代碼爲我感到高興。

+0

這是爲了回答你的問題嗎?如果沒有,那麼你應該使用編輯鏈接來編輯你的問題,並將這些額外的信息添加到你的問題。 – jfriend00

+0

V8可以跨進大約半年的異步執行堆棧,並具有異步堆棧跟蹤 - 儘管在節點中尚未使用它們。 –

+1

我更新了包含我的修復程序的響應。我都必須使用0.11語法的語法 – bdougie

相關問題