Promises does not work as expected
See original GitHub issueRequester 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:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@johvahn2 you probably do
cb(result)
but the first param is reserved for the error. can you trycb(null, result)
?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.