question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Promises does not work as expected

See original GitHub issue

Requester calls Promise.reject() for all responses which evaluate to true.

Following snippet reproduces the issue:

const cote = require('cote')

const resp = new cote.Responder({
  name: 'responder'
}).on('status', (req, cb) => {
  console.log(`Request: ${req.type}`)
  cb('OK')
})

const req = new cote.Requester({
  name: 'requester'
})

req.send({type: 'status'})
  .then(
    data => console.log(`Response: ${data}`),
    err => console.error(`ERROR: ${err}`)
  )

output:

Request: status
ERROR: OK

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
dasherswcommented, Apr 11, 2018

@johvahn2 you probably do cb(result) but the first param is reserved for the error. can you try cb(null, result)?

1reaction
dasherswcommented, Mar 26, 2018

If you’re mixing promises with callbacks, the first parameter in the callback has to always be the error. If you only use callbacks, then you don’t have to adhere to this rule.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Javascript Promises not working As Expected [duplicate]
The key thing to understand here is that promises are always guaranteed to resolve at the end of the current run (i.e. the...
Read more >
Error handling with promises - The Modern JavaScript Tutorial
The program in the task will work as expected if it rewritten like below. In the task an error is thrown form inside...
Read more >
Testing Asynchronous Code - Jest
If you don't use promises, you can use callbacks. For example, let's say that fetchData , instead of returning a promise, expects a...
Read more >
Promise.all() - JavaScript - MDN Web Docs
The Promise.all() method takes an iterable of promises as input and returns a single Promise . This returned promise fulfills when all of ......
Read more >
Velo: Working with Promises | Help Center | Wix.com
When a Promise does not resolve successfully, it is said to reject. You can handle rejections by adding a catch() to the end...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found