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

await client.send({ type: 'time' }) promise always rejects #180

Closed
gerkirill opened this issue Jul 8, 2019 · 2 comments · May be fixed by hixio-mh/cote#2
Closed

await client.send({ type: 'time' }) promise always rejects #180

gerkirill opened this issue Jul 8, 2019 · 2 comments · May be fixed by hixio-mh/cote#2
Labels

Comments

@gerkirill
Copy link

If I use an async / await approach in the time-service client example - the promise always rejects. The error contains a proper response from the time-server though.

client.js example:

const cote = require('cote');
const client = new cote.Requester({ name: 'Client' });

(async() => {
  try {
    const time = await client.send({ type: 'time' });
    console.localStorage(time);
  } catch (e) {
    console.log('ERROR');
    console.error(e);
  }
})();

I believe that's because axon's send() method uses callback(result) convention, while requester.js expects callback(err, result) convention.
Also, the typings for cote declare send() method as one expecting callback(error, result). But it is not the case according to the docs anymore.

@dashersw
Copy link
Owner

dashersw commented Jul 8, 2019

If you're making use of promises (as in the case of async/await) and use callbacks in the responder, the first parameter should be the error. If you only use callbacks, there's no such convention. An easy way to fix this is to always use promises or always use callbacks.

The typings are not official, and done by the community. I'd love to have someone correct them.

@gerkirill
Copy link
Author

Ok, thx. Now I see. That's not really clear from the docs, though.

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

Successfully merging a pull request may close this issue.

2 participants