首先让我说我是node.js和Promises的新手。
我正在使用Bluebird来宣传node.js中的一些代码。
原始代码是用C ++编写的(项目名称:sapnwrfc)。我有一个使用回调的工作示例,如下所示:
con.Open(conParams, function(err) {
// some error handling
var func = con.Lookup('ZHELLO_RFC');
console.log(func.Invoke.toString());
func.Invoke({ }, function(err, result) {
console.log(result);
});
});
上面的代码运行得很好,toString()
输出给了我function Invoke() { [native code] }
。我使用下面的蓝鸟宣传它:
var Promise = require('bluebird');
var sapnwrfc = Promise.promisifyAll(require('sapnwrfc'));
// setup
con.OpenAsync(conParams).then(function(err) {
// some error handling
var hello = con.Lookup('ZHELLO_RFC');
console.log(hello.Invoke.toString());
return Promise.promisify(hello.Invoke)({ })
}).then(function(err, result) {
// some error handling
console.log(result);
});
当我运行上面的代码片段时,我在输出中得到了这个:
Unhandled rejection TypeError: Illegal invocation
at tryCatcher (/home/phil/bc_workspace/MyProject/MyCode/node_modules/bluebird/js/release/util.js:16:23)
at ret (eval at makeNodePromisifiedEval (/home/phil/bc_workspace/MyProject/MyCode/node_modules/bluebird/js/release/promisify.js:184:12), <anonymous>:14:23)
at /home/phil/bc_workspace/MyProject/MyCode/sapOnly.js:27:44
at tryCatcher (/home/phil/bc_workspace/MyProject/MyCode/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/home/phil/bc_workspace/MyProject/MyCode/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/home/phil/bc_workspace/MyProject/MyCode/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/home/phil/bc_workspace/MyProject/MyCode/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/home/phil/bc_workspace/MyProject/MyCode/node_modules/bluebird/js/release/promise.js:693:18)
at Promise._fulfill (/home/phil/bc_workspace/MyProject/MyCode/node_modules/bluebird/js/release/promise.js:638:18)
at /home/phil/bc_workspace/MyProject/MyCode/node_modules/bluebird/js/release/nodeback.js:42:21
我错过了什么,或者是否支持本机代码?