I think that toPromise is taking a wrong value
- Dominant language
- JavaScript
- Stars
- 3.4k
- Forks
- 145
- PR merge metrics
- No merged PRs in 30d
Description
Hi good day, I've a class named RPC, here we've this method
```ts
public async send(nber : number) : Promise {
if (!this.stream) {
await this.delay(2);
console.info('RPC not initialized yet...retrying');
await this.send(nber);
}
const correlationId = RPC.generateUuid();
this.channel?.sendToQueue('rpc_queue', Buffer.from(nber.toString()), {correlationId, replyTo: this.queue?.queue});
return this.stream?.find((msg : ConsumeMessage|null) => {
return msg?.properties.correlationId === correlationId;
}).toPromise(Promise);
}
```
when I try to run this code I get this message:
```
Unhandled rejection TypeError: self._rpc is not a function
at /Users/Admin/Downloads/proj/avanti/bita_dashboard_websocket_backend/node_modules/amqplib/lib/channel_model.js:171:10
at tryCatcher (/Users/Admin/Downloads/proj/avanti/bita_dashboard_websocket_backend/node_modules/bluebird/js/release/util.js:16:23)
at Function.Promise.fromNode.Promise.fromCallback (/Users/Admin/Downloads/proj/avanti/bita_dashboard_websocket_backend/node_modules/bluebird/js/release/promise.js:209:30)
at C.consume (/Users/Admin/Downloads/proj/avanti/bita_dashboard_websocket_backend/node_modules/amqplib/lib/channel_model.js:170:18)
at Stream._generator (/Users/Admin/Downloads/proj/avanti/bita_dashboard_websocket_backend/node_modules/highland/lib/index.js:4938:15)
at Stream._runGenerator (/Users/Admin/Downloads/proj/avanti/bita_dashboard_websocket_backend/node_modules/highland/lib/index.js:1354:10)
at Stream._resume (/Users/Admin/Downloads/proj/avanti/bita_dashboard_websocket_backend/node_modules/highland/lib/index.js:1188:22)
at Stream._checkBackPressure (/Users/Admin/Downloads/proj/avanti/bita_dashboard_websocket_backend/node_modules/highland/lib/index.js:1101:10)
at Stream._resume (/Users/Admin/Downloads/proj/avanti/bita_dashboard_websocket_backend/node_modules/highland/lib/index.js:1182:33)
at Stream._checkBackPressure (/Users/Admin/Downloads/proj/avanti/bita_dashboard_websocket_backend/node_modules/highland/lib/index.js:1101:10)
at Stream._resume (/Users/Admin/Downloads/proj/avanti/bita_dashboard_websocket_backend/node_modules/highland/lib/index.js:1182:33)
at Stream._checkBackPressure (/Users/Admin/Downloads/proj/avanti/bita_dashboard_websocket_backend/node_modules/highland/lib/index.js:1101:10)
at Stream._resume (/Users/Admin/Downloads/proj/avanti/bita_dashboard_websocket_backend/node_modules/highland/lib/index.js:1182:33)
at Stream.resume (/Users/Admin/Downloads/proj/avanti/bita_dashboard_websocket_backend/node_modules/highland/lib/index.js:1216:10)
at /Users/Admin/Downloads/proj/avanti/bita_dashboard_websocket_backend/node_modules/highland/lib/index.js:2146:13
at new Promise ()
```
very weird that `self._rpc` is not a function because I don't have anything like that in my code, after check the code seems that I'm not passing the right PromiseCtor but I don't know what must I pass to this method
```js
Stream.prototype.toPromise = function (PromiseCtor) {
var self = this;
return new PromiseCtor(function(resolve, reject) {
self.consume(toCallbackHandler('toPromise', function(err, res) {
if (err) {
reject(err);
}
else {
resolve(res);
}
})).resume();
});
};
exposeMethod('toPromise');
```
I even try pass a bluebird promise but I get the same message: self._rpc is not a function
do you know what am I doing wrong?...thank you so much!!!
Contributor guide
Research direction
Start with the RPC.send method in the report and Highland's Stream.prototype.toPromise implementation, then trace the self.consume call into the amqplib and Bluebird stack frames shown. Reproduce the error with the reported Promise constructor choices and determine what valid constructor or invocation makes the stream resolve without the self._rpc failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js, typescript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100