-
Notifications
You must be signed in to change notification settings - Fork 0
/
asynexample.js
36 lines (35 loc) · 939 Bytes
/
asynexample.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// https://blog.cloudboost.io/execute-asynchronous-tasks-in-series-942b74697f9c
function seriesDemo(req, res, next) {
const saveRequest = async() => {
const company = new Company({
name: 'FullStackhour'
});
const savedCompany = await company.save();
const job = new Job({
title: 'Node.js Developer',
_company: savedCompany._id
});
const savedJob = await job.save();
const application = new Application({
_job: savedJob._id,
_company: savedCompany._id
});
const savedApp = await application.save();
const licence = new Licence({
name: 'FREE',
_application: savedApp._id
});
const savedLic = await licence.save();
return {
company: savedCompany,
job: savedJob,
application: savedApp,
savedLic: licence
};
}
saveRequest()
.then(result => {
return res.json(result);
})
.catch(err => next(err));
}