kaotkbliss Posted February 15, 2019 Posted February 15, 2019 I have to functions, each return a promise. I need to execute the first function 2x, then when it's done, execute the 2nd function 2x currently it's set up in this format async function somename (parameters) { promise = new Promise((resolve, reject)=> { do stuff; }; complete = await promise; }; async function somename2 (parameters) { promise = new Promise((resolve, reject)=> { do stuff; }; complete = await promise; }; somename(parameters).then((onReturn) => { somename(newparameters).then((onReturn) => { somename2(parameters).then((onReturn) => { somename2(newparameters).then((onReturn) => { do stuff; }) }) }) }) Ideally I'd like to just call the first function 2x, then wait for both to finish, then call the next one 2x and wait for both of those to finish. That way each pair of functions is running at the same time. 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy!
kaotkbliss Posted February 20, 2019 Author Posted February 20, 2019 Managed to figure this out async function somename (parameters) { promise = new Promise((resolve, reject)=> { do stuff; resolve (return val); }; complete = await promise; }; async function somename2 (parameters) { promise = new Promise((resolve, reject)=> { do stuff; resolve (return val); }; complete = await promise; }; let getSomename = async (parameters, newParameters) => { await somename(parameters); await somename(newParameters); return (some val); }; let getSomename2 = async (parameters, newParameters) => { await somename2(parameters); await somename2(newParameters); return (some val); }; getSomename(parameters, newParameters).then((onReturn) => { getSomename2(parameters, newparameters).then((onReturn) => { do stuff; }) }) 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now