Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

repeat async call n times in js

const repeatCall = (call, {
  repeat = 1,
  params = []
}) => {

  const calls = [];

  for (let i = 0; i < repeat; i++) {
    calls.push(call(...params));
  }
  return calls;
}

const asyncFunc = async (param1, param2) => {
  return await something();
}

Promise.all(
  repeatCall(
    asyncFunc,
    {
      repeat: 10, // repeat call ten times
      params: [param1Value, param2Value],
    }
  ))
  .then((responses) => {
    // do something with array of 10 responses 
  })
Comment

PREVIOUS NEXT
Code Example
Javascript :: hide playback speed from videojs 
Javascript :: popos not showing applications 
Javascript :: open link in a new tab progmatically 
Javascript :: set to array casting js 
Javascript :: searchbar to bottom table datatable 
Javascript :: javascript multiple cases 
Javascript :: symbol properties javascript 
Javascript :: javascript match against array 
Javascript :: javascript && operator 
Javascript :: how to migrate data from one elasticsearch to another 
Javascript :: chai async test 
Javascript :: video recorder using webrtc and javascript 
Javascript :: comment faire pour écrire un texte en javascript 
Javascript :: string to number javascript 
Javascript :: override backswipe behaviour in ios and android react native 
Javascript :: two dimensional array traversing in javascript 
Javascript :: div diseapear animation 
Javascript :: node.js process.argv 
Javascript :: js contains 
Javascript :: opacity material ui 
Javascript :: VS Code Auto Import is bugging usestate 
Javascript :: input mask 9 number add 
Javascript :: how to check with jquery if bootstrap modal is hidden or shown 
Javascript :: obfuscate js code 
Javascript :: how to take yes or no in js 
Javascript :: react hooks in codepen 
Javascript :: escape double quotes in json 
Javascript :: ajax post csrf codeigniter 
Javascript :: node start is too slow windows 10 
Javascript :: .html jquery in javascript 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =