Multiple next with non async function
See original GitHub issueHi,
I wrote test like below, it throw an error but it come like this
UnhandledPromiseRejectionWarning: Error: next() called multiple times
and the test failed. Is this expected?
it(`should throw if next() is called multiple times in non async function`, async () => {
const stack = [];
stack.push((ctx, next) => {
next();
next();
});
expect.hasAssertions();
try {
await compose(stack)({});
} catch (error) {
expect(error).toBeInstanceOf(Error);
}
});
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Using "await" inside non-async function - Stack Overflow
My problem is I'd like the synchronous function to be able to wait for a value from the async one... They can't, because:....
Read more >JavaScript async and await - in plain English, please
JavaScript developers love using async-await . It is the most straightforward way to deal with asynchronous operations in JavaScript.
Read more >async function - JavaScript - MDN Web Docs - Mozilla
The async function declaration declares an async function where the await keyword is permitted within the function body. The async and await ...
Read more >How to escape async/await hell - freeCodeCamp
While working with Asynchronous JavaScript, people often write multiple statements one after the other and slap an await before a function call.
Read more >Asynchronous programming in C# | Microsoft Learn
An overview of the C# language support for asynchronous programming using async, await, Task, and Task.
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
No, koa-compose support sync calls. The problem here is
next()
return a Promise. We need return Promise or include it in async function (had been included in test case).The following one is use promise-based sync function.
@Runrioter that’s exactly what I ment (I maybe expressed it badly). If you’re dealing with them as promises the request chain isn’t synchronous, the execute on a new tick.