Category : asynchronous

In Postman, I run an arbitrary request. I put the following code in either the Pre-req. script or in the Tests script: fetch(‘https://jsonplaceholder.typicode.com/todos/3’) .then(response => response.text()) .then(responseBody => { console.log(‘The response body:’); console.log(responseBody); }); When I hit the Send button to run the request, I get ReferenceError: fetch is not defined: When searching online, I ..

Read more

How do one change the following promise function into a async function. const createRecord = (record) =>{ return new Promise((resolve)=>{ queue.push({ id: Math.floor(Math.random()*100), callback: (id)=>{resolve(id);}, data: record }); }); }; I’ve tried the following code, but the function completes before the callback completes. const createRecord = async (record) =>{ queue.push({ id: Math.floor(Math.random()*100), callback: (id)=>{return id;}, ..

Read more

Let’s say I have this async.parallel code example below, to run parallel mongoose queries. async.parallel({ one: (callback) => {Car_Model.findOne({location: "location1"}).select({ id: 1 });}, two: (callback) => {Car_Model.findOne({location: "location2"}).select({ id: 1 });}, three: (callback) => {Car_Model.findOne({location: "location3"}).select({ id: 1 });}, },(err,results) => { if (err) { /* … error handling code */ } /* … continued ..

Read more

Hello I need help on my code. I am not really familiar with Promises. I created a function called EmitRandomNumber(). In this function, after 2 full seconds (2000 ms), it generates a random number between 0 to 100. If the random number generated is below 80, I need to call that function again, up to ..

Read more

I apologize for my English in advance (if it’s overwhelming to understand) But basically this is what I’ve written: let aop = [ ‘https://api.coindesk.com/v1/bpi/currentprice.json’, ‘https://datausa.io/api/data?drilldowns=Nation&measures=Population’, ‘https://api.publicapis.org/entries’]; (async function (){ Promise.all(aop.map(async url => { let response = await fetch(url); let json = await response.json(); return json; })).then(x => console.log(x)) } ()); (function functionThatTakes30SecondsToFinish (){ // Some ..

Read more