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 7910959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:04:05+00:00 2026-06-03T13:04:05+00:00

Having an object to store data. var store = { elements: [], eventsEnabled: true,

  • 0

Having an object to store data.

var store = {
    elements: [],
    eventsEnabled: true,
    addElement: function(element) {
        this.elements.push(element);
        if (this.eventsEnabled) {
            // Code that triggers event, calls handlers... whatever
        }
    }
};

The act of storing data comes from two events (kind of two producers). First “producer” does not trigger any event:

setInterval(function() {
    store.eventsEnabled = false;
    store.addElement('hello');
    store.eventsEnabled = true;
}, 12000);

Second does trigger events:

setInterval(function() {
    store.addElement('bye');
}, 7000);

The question is, can the second producer break execution flow of first producer?

I mean, if producer 1 disables events and, before finishing execution (and therefore before events are enabled again), producer 2 starts its execution and adds its element, then no events will be triggered. Is that possible? Can that happen?

If so, how can this code be converted to be kind-of thread-safe?

  • 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-06-03T13:04:10+00:00Added an answer on June 3, 2026 at 1:04 pm

    JavaScript is single-threaded. A function cannot be interrupted, so you can be sure each function block will complete before another begins.

    (However, if a function makes an asynchronous call, other functions may execute before the asynchronous operation starts. That doesn’t happen in your code, though, that I can see, besides the setTimeout calls, and you can be sure those will execute in the correct order.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having problems while saving a pre-persisted JDO object in google-app-engine data store.
In MVC app, I am having this big object that is used in classic
I am having trouble with the following code: function Class() { var self =
I'm having an entity object called Patient and this entity is having a property
Having a list of data object and something visual to represent each, where would
Having a snippet like this: import yaml class User(object): def __init__(self, name, surname): self.name=
Quick question: Is there a per-user data storage object (similar to Session ) that
We are in evaluating technologies that we'll use to store data that we gather
I'm having a really confounding problem using Core Data. In my Core Data store,
I want to add metadata to my object graph for non-domain type data that

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.