async-express
Advanced tools
Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "async-express", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Allow async/await syntax in Express routes and middleware", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -18,11 +18,11 @@ # async-express | ||
// As a route | ||
app.get('/', _async((req, res, next) => { | ||
app.get('/', _async(async (req, res, next) => { | ||
// Wait 5 seconds | ||
await new Promise(r => setTimeout(r, 5000)); | ||
// Send a response | ||
req.send('Waited 5 seconds successfully'); | ||
res.send('Waited 5 seconds successfully'); | ||
})); | ||
``` | ||
The sample above can be refactored using decorator syntax as the following | ||
The sample above can be refactored as the following | ||
@@ -37,9 +37,8 @@ ```js | ||
@_async | ||
function waitForABit(req, res, next) { | ||
const waitForABit = _async(async (req, res, next) => { | ||
// Wait 5 seconds | ||
await new Promise(r => setTimeout(r, 5000)); | ||
// Send a response | ||
req.send('Waited 5 seconds successfully'); | ||
} | ||
res.send('Waited 5 seconds successfully'); | ||
}); | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1338
43