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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:50:53+00:00 2026-05-25T20:50:53+00:00

I need to implement the queue of events (=updates on the server). New events

  • 0

I need to implement the queue of events (=updates on the server). New events will be added to this queue when user changes the slider, presses buttons etc. Each event will contain the following properties:

  1. device id (the action will be applied to that device on the server)
  2. action (set, get etc.)
  3. value (the value, which should be used in the action)

New event should be added there at the end. But in case there is already event for the same device id and with the same action, then this event should be updated with new value. How should I do that?

I’ve drafted the following:

var inCall = false;
var queueArrayDevices = new Array();
var queueArrayActions = new Array();
var queueArrayValues = new Array();

// add call to the queue, at the end
function addAPICall(device, action, value){
    // should NOT add event here, if device and action already exists
    // should update the value instead
    queueArrayDevices.push(device);
    queueArrayAсtions.push(action);
    queueArrayValues.push(value);
}

function doAPICall(device, action, value){    
    inCall = true;
    // call server here
    // if not successful, we should add this item to the queue again
    inCall = false;
}

function callAPIQueue(){
    if(!inCall && queueArrayDevices.length > 0){
        device = queueArrayDevices.shift();
        action = queueArrayAсtions.shift();
        value = queueArrayValues.shift();
        doAPICall(device, action, value);        
    }
}

// start queue processing
setInterval(callAPIQueue, 400);

I use jquery mobile, probably it can help me to simplify such queue creation?

  • 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-25T20:50:54+00:00Added an answer on May 25, 2026 at 8:50 pm

    First of, you should only have one array holding an event object, otherwise you are really over complicating it for yourself.

    next just loop over the events and see if one of the same device/action already exists when a new event is added.

    try to do it something like this:

    var inCall = false;
    var queue = [];
    
    // add call to the queue, at the end
    function addAPICall(device, action, value){
      var found=false;
      for(var i=0, event; event = queue[i]; i++) {
        if(event.action == action && event.device == device) {
          event.value = value;
          found = true;
          break;
        }
      }
      if(!found) {
        queue.push({device: device, action: action, value: value});
      }
    }
    
    function doAPICall(device, action, value){    
        inCall = true;
        // call server here
        // if not successful, we should add this item to the queue again
        inCall = false;
    }
    
    function callAPIQueue(){
        if(!inCall && queueArrayDevices.length > 0){
        var event = queue.shift();
            doAPICall(event.device, event.action, event.value);        
        }
    }
    
    // start queue processing
    setInterval(callAPIQueue, 400)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to implement a FIFO queue for messages on a game server so
I need to implement a Diff algorithm in VB.NET to find the changes between
I need to implement an in-memory tuple-of-strings matching feature in C. There will be
I need to implement the classic Factory Method pattern in ASP.NET to create server
I need to implement a priority queue in C programming using singly linked list.
I need to implement a basic FIFO queue of objects. Whats the best built-in
I am currently trying to implement a job queue in php. The queue will
I'm writing a win32 library and I need to implement a producer-consumer queue using
I need to implement a TCP client application. The client and the server send
I need to implement posting some data to a web server in the background.

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.