2014-06-19 2 views
1

ddpclientwhen.js을 사용하려고합니다. 필자가 작성한 코드는 게시물 하단에 있습니다. 이것을 사용하려고하면 다음 오류가 발생합니다. 이 오류를 해결하는 방법에 대한 아이디어가 있습니까? 약속을 사용하는 또 다른 DDPclient을 알고 있지만 추가 약속 라이브러리를 추가하지는 않습니다. 아래약속과 함께 DDPClient를 어떻게 사용합니까?

Potentially unhandled rejection TypeError: Object #<Object> has no method '_nextId' 
    at DDPClient.call (/Source/proj/node_modules/ddp/lib/ddp-client.js:329:17) 
    at /Source/tellme/updater/node_modules/when/node.js:89:7 
    at tryCatchReject (/Source/proj/node_modules/when/lib/makePromise.js:790:14) 
    at FulfilledHandler.when (/Source/tellme/updater/node_modules/when/lib/makePromise.js:621:9) 
    at ContinuationTask.run (/Source/tellme/updater/node_modules/when/lib/makePromise.js:741:24) 
    at Scheduler._drain (/Source/proj/node_modules/when/lib/scheduler.js:56:14) 
    at Scheduler.drain (/Source/proj/node_modules/when/lib/scheduler.js:21:9) 
    at process._tickCallback (node.js:419:13) 
    at Function.Module.runMain (module.js:499:11) 
    at startup (node.js:119:16) 

코드 :

"use strict"; 
var when   = require('when'), 
    node   = require('when/node'), 
    DDPClient  = require('ddp'); 


var ddpclient = new DDPClient({ 
    host: "localhost", 
    port: 3000 
}); 

var ddpconnect = node.lift(ddpclient.connect); 
var ddpcall = node.lift(ddpclient.call); 

//var ddpConnectPromise = node.lift(ddpclient.connect); 

var obj = {"name": "john","age":25}; 

when(ddpconnect).then 
(ddpcall("processObj", obj)). 
    catch(function (error) { 
     console.log(error); 
    }). 
    done(); 

편집 : 다음은 가까이 날 잡으려고 나타납니다,하지만 난 발생 [형식 오류를 : processObj가있는 방법 '의 addListener'이없는 오브젝트] 오류가 발생했습니다. 당신이 bluebird를 사용 괜찮다면

"use strict"; 
var when   = require('when'), 
    node   = require('when/node'), 
    DDPClient  = require('ddp'); 

var ddpConnectPromise = node.liftAll(DDPClient); 

var ddpclient = new ddpConnectPromise({ 
    host: "localhost", 
    port: 3000 
}); 

var obj = {"name": "john","age":25}; 
when(ddpclient.connect).then(function (ddpclient) { 
    ddpclient.call("processObj", sampleJSON); 
}). 
    catch(function (error) { 
     console.log(error); 
    }). 
    done(); 
+0

[이 잘 작동하지 않습니다 프로토 타입 객체에'liftAll'를 사용하는 것 같습니다.] (https://github.com/cujojs/when/issues/294) – user3374348

답변

0

, 그것은 promisifyAll을 가지고 당신은 사용할 수 있습니다

var Promise = require("bluebird"); 
Promise.promisifyAll(require("ddp").prototype); 
var DDPClient = require("ddp");  

var ddpclient = new DDPClient({ 
    host: "localhost", 
    port: 3000, 
    /* optional: */ 
    auto_reconnect: true, 
    auto_reconnect_timer: 500, 
    use_ejson: true,   // Use Meteor's EJSON to preserve certain data types. 
    use_ssl: false, 
    maintain_collections: true // Set to false to maintain your own collections. 
}); 


var obj = {"name": "john","age":25}; 

ddpclient.connectAsync().then(function(ddpclient) { 
    return ddpclient.callAsync("process", {}); // params is a required argument 
}).then(function(callResult) { 

}); // Logging errors is useless when using bluebird, so leave the .catch out 
+0

나는 언제 붙들려하고 싶지만 위와 상관없이 시도해 보았습니다. 그러나 다음 오류가 발생했습니다 : TypeError : Object [object Object] 'connectAsync'메서드가 없습니다. promisify는 프로토 타입과도 잘 작동하지 않을까요? – user1074891

+0

몇 가지 모드가 끝난 후 비동기 메서드가 있습니다. connectAsync는 다음 함수로 전달할 수있는 어떤 것도 반환하지 않는 것처럼 보입니다. – user1074891

+0

@ user1074891 promisify가 대답과 같이 작동합니다. 그렇지 않으면 When.js를 사용할 수 있습니다. – Esailija

관련 문제