Yehonatan

Asnyc/Await/Promise

Nov 12th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. async function controllerMethod(req, res) {
  2.  let data = await getAllAsync();
  3.  res.send(data);
  4. }
  5.  
  6. function getAllPromised() {
  7.   return new Promise((resolve, reject) => {
  8.     getData('http://url.com').then(data => {
  9.        resolve(data);
  10.     });
  11.   });
  12. }
  13.  
  14. async function getAllAsync() {
  15.   let data = await getData('http://url.com');
  16.   return data;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment