Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6894295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:45:54+00:00 2026-05-27T06:45:54+00:00

I know, using the words JavaScript and ‘atomic’-anything in the same sentence is kinda

  • 0

I know, using the words JavaScript and ‘atomic’-anything in the same sentence is kinda strange, since JavaScript is prised to be asynchronous and therefor not very atomic.

//EDIT
This was a mistake on my side! by having alert’s going off (and hiding further alerts in chrome) it quickly interrupted and let other code fly. JavaScript is single-threaded.

Quick -> Actual Question;
in which situation are we save from async callback interrupts and how could we prevent them for certain code blocks?

Long -> My Scenario;
My whole application is very recursive and triggers many ajax requests, that on returns, triggers many more recursive functions that may trigger more ajax requests.
In my Code, I have some very crucial operations on an array, that have to complete before the next operation can happen (simple push/splice logic though).

I had a problem, where I got the index of a key within an array and saved it in a variable. I then compared it to -1 and if it was true, I spliced (not just unset) the element from the array.
Now, in between getting the index and splicing, the asynchronous callback returned with results and started recursive stuff, which then altered the array by adding/removing further items (and messing up the index value I got before).

This was the old code;

if ( this.dataset && (index=this.dataset.children.indexOf(child.key) )!==-1 ){
    console.log("removed from dataset!");
    //<=== AJAX Call Returns and adds/removes items from the array
    this.dataset.children.splice(index, 1); //goes bad, because index not good anymore
    ...
}

and this is the ‘working’, but not optimized code

if ( this.dataset && (index=this.dataset.children.indexOf(child.key) )!==-1 ){
    console.log("removed from dataset!");  
    //<=== AJAX Call Returns and adds/removes items from the array
    //Problem solved, since I'm getting the index again
    this.dataset.children.splice(this.dataset.children.indexOf(child.key), 1);
    ...
}

I just simply search for the index again and directly splice it away.

my general question is, in which situation are we save from async callback interrupts and how could we prevent them for certain code blocks?

My specific question, fellow StackOverflowers, is if in theory, the ajax callback could be called in between the indexOf function returning the index and the splice function cutting the array up.

Thank you for your help

p.S I am aware, that I just could unset the array field and my index problem would be solved. But that’s not what I want, since I’m serialising that information and don’t want 100ths of empty entries. Finding a general way how to tackle such situations is my goal 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:45:54+00:00Added an answer on May 27, 2026 at 6:45 am

    JavaScript is inherently single-threaded. This means that if AJAX response arrives or timeout/interval should be triggered but other code is running, the response callback/timeout will wait.

    This was one of the primary reasons why JavaScript was chosen for node.js.

    See also:

    • Are there any atomic javascript operations to deal with Ajax's asynchronous nature?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to know how many words a paragraph contains using Jquery or Javascript? What
does anybody know how can I sort words in string using javascript, jquery. For
How does operating system know what filesystem a partition is using? In other words,
I'm not particular familiar with using jQuery/Javascript so I don't know what the best
I need to count words in a string using PHP or Javascript (preferably PHP).
I know it's possible to match a word and then reverse the matches using
In Django, I know using filter with multiple arguments gets translated into SQL AND
Friends, I like to know using which version of Android SDK we can develop
I know that using continuous integration improves the quality of my code base, and
I know about using a -vsdoc.js file for IntelliSense , and the one for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.