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

  • Home
  • SEARCH
  • 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 6157339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:46:06+00:00 2026-05-23T20:46:06+00:00

I am building a real-time system which (with a use of websockets) updates a

  • 0

I am building a real-time system which (with a use of websockets) updates a table with live data of different frequencies (can be 3 times per second, can be once every 2 seconds – dependant on the type of data).
I am currently struggling to find a way of letting the user know when a particular field has not been updated in the last 5 seconds. That is, if no new data is fetched, I shouldn’t keep the old value there, but rather change it to ‘–‘ or something similar.

After a long way to the javascript, final function which updates fields looks like that (extremely simplified):

function changeValue(data){
        var fieldId= data.fieldId;
        var value = Math.round(data.value);
        $('span#'+fieldId).text(value);
}

This function gets called each time a field needs to be changed. I’ve got between 2 and 40 different fields (dependant on the user) that are changed.

What is the best way of setting timers in order to change the values of the fields to ‘–‘ every 5 seconds, if no update has been made?

I would be really grateful for some tips,
Thanks,
Karol.

  • 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-23T20:46:07+00:00Added an answer on May 23, 2026 at 8:46 pm

    Since you want to indicate timeout on a per-field basis, you have two obvious options:

    1. Have a global interval timer that ticks over fairly frequently and looks through all of your fields for a timeout.
    2. Have independent timers for each field which just deal with that field.

    I think on balance I prefer (1) to (2), because we’re only dealing with one interval timer then and it makes the housekeeping simpler.

    Since IDs in documents must be unique, we can use your field ID values as a key in a hash (an object) to store last updated times. This is kind of a spin on the previous answer but works on a per-field basis. So here’s how we’d set those last updated times:

    var lastUpdatedTimes = {};
    
    function changeValue(data){
            var fieldId= data.fieldId;
            var value = Math.round(data.value);
            $('span#'+fieldId).text(value);
            lastUpdatedTimes[fieldId] = new Date().getTime();
    }
    

    Then you set up an interval timer to check each of them.

    function checkFieldsForTimeout(){
            var now = new Date.getTime();
    
            // For each ID in lastUpdatedTimes, see if 'now minus
            // last updated' is > 5000 and is so, set the field
            // text to '--' and remove that entry from the last
            // updated list with "delete lastUpdatedTimes[itemId]".
    }
    

    Should a timed-out field spring back to life, the “–” will be replaced by some real text again.

    By deleting the last updated time from “lastUpdatedTimes” whenever we put “–” into a field, we make sure that the interval timer isn’t wasting time processing fields that have already been timed out.

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

Sidebar

Related Questions

I'm building a real-time GPS tracking system, which will receive GPS data sent from
I'm building an iOS app which needs real-time updates from the server, and I'd
I am building a real-time reservation system and would like to allow users to
I am building a system in Clojure that consumes events in real time and
I'm building a system to show a bit of real time activity on a
We are building a financial web application which requires a real time chart. Initially
I'm building a real time game, mostly chat based, and I need to have
I am building a web application that has a real-time feed (similar to Facebook's
Real-life case (helps understand the question) I am building a device that can freely
I am building a website that has a system where users can send messages

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.