eaglehopes Posted June 26, 2023 Share Posted June 26, 2023 (edited) Is there any similarity between promises and async-threads in java(or any other lang)? Edited June 26, 2023 by eaglehopes chose more suitable word Quote Link to comment https://forums.phpfreaks.com/topic/317012-how-do-promises-program-flow-work-in-javascript/ Share on other sites More sharing options...
Solution requinix Posted June 26, 2023 Solution Share Posted June 26, 2023 Basically anything that has "await" and/or "async" keywords works the same way. Quote Link to comment https://forums.phpfreaks.com/topic/317012-how-do-promises-program-flow-work-in-javascript/#findComment-1610021 Share on other sites More sharing options...
Strider64 Posted June 26, 2023 Share Posted June 26, 2023 "await" is great if you need have all the data before you moving on especially good when developing a game. // Fetch the First ID const fetchFirstId = async () => { try { // fetch the data from the server const response = await fetch('get-first-id.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({resetScore: false}) }); // parse the response as JSON const data = await response.json(); id = data.first_id; // Grab the First ID the DB Table //console.log(id); await changeImageSource(data.image); await fetchQuestion(); await fetchWord(); // fetch the answers //await fetchImage(); } catch (error) { console.error(error); } }; Quote Link to comment https://forums.phpfreaks.com/topic/317012-how-do-promises-program-flow-work-in-javascript/#findComment-1610023 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.