Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I think that toPromise is taking a wrong value #706

Open
cocodrino opened this issue Jul 14, 2020 · 1 comment
Open

I think that toPromise is taking a wrong value #706

cocodrino opened this issue Jul 14, 2020 · 1 comment

Comments

@cocodrino
Copy link

Hi good day, I've a class named RPC, here we've this method

  public async send(nber : number) : Promise<ConsumeMessage> {
    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 (<anonymous>)


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

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!!!

@iliocatallo
Copy link

Hi @cocodrino,

Might it be that the Promise in .toPromise(Promise) is not global.Promise? Maybe something is shadowing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants