socket.io control execution order with nested async and awaitHttpClient.GetAsync(…) never returns when using await/asyncasync/await - when to return a Task vs void?Using async/await for multiple tasksHow and when to use ‘async’ and ‘await’ContextBoundObject with Async/AwaitConfusion with async/await web calls in orderUsing async/await with a forEach loopAsync/Await Mongoose doesn't always run correctlyJavascript async await not waiting for mongoose awaitHow to execute socket.io endpoints sychronously

What are the purposes of autoencoders?

copy and scale one figure (wheel)

Has any country ever had 2 former presidents in jail simultaneously?

Loading commands from file

What should you do if you miss a job interview (deliberately)?

Start making guitar arrangements

What is Cash Advance APR?

Why Shazam when there is already Superman?

Create all possible words using a set or letters

Why is so much work done on numerical verification of the Riemann Hypothesis?

When were female captains banned from Starfleet?

What is this called? Old film camera viewer?

What does chmod -u do?

How to explain what's wrong with this application of the chain rule?

What if a revenant (monster) gains fire resistance?

What was this official D&D 3.5e Lovecraft-flavored rulebook?

If a character has darkvision, can they see through an area of nonmagical darkness filled with lightly obscuring gas?

Count the occurrence of each unique word in the file

Why electric field inside a cavity of a non-conducting sphere not zero?

The screen of my macbook suddenly broken down how can I do to recover

Did arcade monitors have same pixel aspect ratio as TV sets?

How to bake one texture for one mesh with multiple textures blender 2.8

Can I sign legal documents with a smiley face?

What was the exact wording from Ivanhoe of this advice on how to free yourself from slavery?



socket.io control execution order with nested async and await


HttpClient.GetAsync(…) never returns when using await/asyncasync/await - when to return a Task vs void?Using async/await for multiple tasksHow and when to use ‘async’ and ‘await’ContextBoundObject with Async/AwaitConfusion with async/await web calls in orderUsing async/await with a forEach loopAsync/Await Mongoose doesn't always run correctlyJavascript async await not waiting for mongoose awaitHow to execute socket.io endpoints sychronously













0















In my app, I have multiple users submitting data "at once" via a socket.event.
Because I need to know if every user has submitted their data successfully, I try to indentify the first and last entry.
For that, I call an async function on the event, which itself includes "await".



Basically, the function looks for a value in the database and then does something depending on whether it exists or not.



Because of that, I need the function block (with its awaits) to be fully executed before the next instance of the function is called.



However, what I found is that the as soon as I call await inside the function, the next instance of said function starts executing, which obviously messes everything up.



 socket.on("entries", async entries => 

const firstEntry = await match.noEntries(mid);
if (firstEntry)
//do sth


await match.submitEntries(mid, socket.pid, entries);

);

//FUNCTION

noEntries: async (mid) =>
const entries = await database.query("...");
return (entries.length == 0);



Is there any way I can prevent the next instance of the function to be executed before it's predecessor has finished?



Thanks in advance!










share|improve this question






















  • let me ask to see if I got your question. So you basically want to execute every callback from your "entries" even synchronously between them (like one after another), although each callback are asynchronous by itself?

    – Gonzalo.-
    2 days ago











  • yes, that's on point

    – Hylaze
    yesterday















0















In my app, I have multiple users submitting data "at once" via a socket.event.
Because I need to know if every user has submitted their data successfully, I try to indentify the first and last entry.
For that, I call an async function on the event, which itself includes "await".



Basically, the function looks for a value in the database and then does something depending on whether it exists or not.



Because of that, I need the function block (with its awaits) to be fully executed before the next instance of the function is called.



However, what I found is that the as soon as I call await inside the function, the next instance of said function starts executing, which obviously messes everything up.



 socket.on("entries", async entries => 

const firstEntry = await match.noEntries(mid);
if (firstEntry)
//do sth


await match.submitEntries(mid, socket.pid, entries);

);

//FUNCTION

noEntries: async (mid) =>
const entries = await database.query("...");
return (entries.length == 0);



Is there any way I can prevent the next instance of the function to be executed before it's predecessor has finished?



Thanks in advance!










share|improve this question






















  • let me ask to see if I got your question. So you basically want to execute every callback from your "entries" even synchronously between them (like one after another), although each callback are asynchronous by itself?

    – Gonzalo.-
    2 days ago











  • yes, that's on point

    – Hylaze
    yesterday













0












0








0








In my app, I have multiple users submitting data "at once" via a socket.event.
Because I need to know if every user has submitted their data successfully, I try to indentify the first and last entry.
For that, I call an async function on the event, which itself includes "await".



Basically, the function looks for a value in the database and then does something depending on whether it exists or not.



Because of that, I need the function block (with its awaits) to be fully executed before the next instance of the function is called.



However, what I found is that the as soon as I call await inside the function, the next instance of said function starts executing, which obviously messes everything up.



 socket.on("entries", async entries => 

const firstEntry = await match.noEntries(mid);
if (firstEntry)
//do sth


await match.submitEntries(mid, socket.pid, entries);

);

//FUNCTION

noEntries: async (mid) =>
const entries = await database.query("...");
return (entries.length == 0);



Is there any way I can prevent the next instance of the function to be executed before it's predecessor has finished?



Thanks in advance!










share|improve this question














In my app, I have multiple users submitting data "at once" via a socket.event.
Because I need to know if every user has submitted their data successfully, I try to indentify the first and last entry.
For that, I call an async function on the event, which itself includes "await".



Basically, the function looks for a value in the database and then does something depending on whether it exists or not.



Because of that, I need the function block (with its awaits) to be fully executed before the next instance of the function is called.



However, what I found is that the as soon as I call await inside the function, the next instance of said function starts executing, which obviously messes everything up.



 socket.on("entries", async entries => 

const firstEntry = await match.noEntries(mid);
if (firstEntry)
//do sth


await match.submitEntries(mid, socket.pid, entries);

);

//FUNCTION

noEntries: async (mid) =>
const entries = await database.query("...");
return (entries.length == 0);



Is there any way I can prevent the next instance of the function to be executed before it's predecessor has finished?



Thanks in advance!







javascript node.js asynchronous socket.io async-await






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 days ago









HylazeHylaze

62




62












  • let me ask to see if I got your question. So you basically want to execute every callback from your "entries" even synchronously between them (like one after another), although each callback are asynchronous by itself?

    – Gonzalo.-
    2 days ago











  • yes, that's on point

    – Hylaze
    yesterday

















  • let me ask to see if I got your question. So you basically want to execute every callback from your "entries" even synchronously between them (like one after another), although each callback are asynchronous by itself?

    – Gonzalo.-
    2 days ago











  • yes, that's on point

    – Hylaze
    yesterday
















let me ask to see if I got your question. So you basically want to execute every callback from your "entries" even synchronously between them (like one after another), although each callback are asynchronous by itself?

– Gonzalo.-
2 days ago





let me ask to see if I got your question. So you basically want to execute every callback from your "entries" even synchronously between them (like one after another), although each callback are asynchronous by itself?

– Gonzalo.-
2 days ago













yes, that's on point

– Hylaze
yesterday





yes, that's on point

– Hylaze
yesterday












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281391%2fsocket-io-control-execution-order-with-nested-async-and-await%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281391%2fsocket-io-control-execution-order-with-nested-async-and-await%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript