Updating/Timer feature for a single feed out of two -- Combining data with $q.all()

I'm revisiting a question I previously asked here.

The approach I took involved using the $q.all() method to resolve multiple http calls and then filtering and merging the data. Everything was working fine, but now I want to refresh one of the feeds every 5 minutes. Usually, I would add a timer at the end of my code like this:

var timer = $scope.intervalFunction = function() {
    $timeout(function() {
       /* function to call $http.get again */
        $scope.intervalFunction(); 
    }, 300000)
}; 
timer(); 
$timeout.cancel(timer); 

My challenge is figuring out how to update just one source without duplicating list items when both sources are merged together. This has been an issue for me in previous attempts.

Any suggestions or insights would be greatly appreciated! Thank you!

JSFiddle link: here

Answer №1

"I'm looking to refresh one of my two feeds every 5 minutes." It may not be possible to achieve this using a single $q.all request. One workaround could be to make an additional request outside of the $q.all wrapper and then initiate a $timeout after receiving results from the first $q.all request.

I should mention that I haven't tested this solution myself, but it might work:

$q.all(promises)
  .then(function(response) { 
    metadata = response.metadataPromise.data;
    metrics = response.metricsPromise.data; 
    joinMetadataAndMetrics();
    requestEveryFiveMinutes(); 
  })
  .catch(function(error) { 
    console.log(error);
  });

function requestEveryFiveMinutes() {
  $interval(function() {
    // Perform the necessary http request here
    yourRequest()
      .then(function() {
        // Handle the response accordingly
      })
      .catch(function(err) {
        console.log(err);
      })
  }, 300000);
}

Don't forget to inject $interval in your controller.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Hover over with your mouse to open and close the dropdown menu in React JS

Just starting out with React JS and encountering a small issue. I'm trying to make the menu disappear when the mouse leaves that area, so I used onMouseOut and onMouseLeave to close it. However, I noticed that having these options in place prevents th ...

I am currently attempting to extract data from a JSON file by using key names for reference, but I am running into issues when dealing with nested keys

Is there a better way to retrieve values from a JSON file by matching key names? The current method I am using does not seem to work with nested keys, so any suggestions on alternative approaches would be appreciated. // Sample .JSON file { "ro ...

Saving props in React-select

I'm currently utilizing react-select to enable multiple selection on my UI. However, I need to extract the props from react-select since I will be sending the selected values to the backend. My query is how can I store the state values in an array for ...

Attempting to wipe out a request using ajax to access relationship entities in a ruby on rails framework

I'm currently working on implementing an ajax request to delete a "budget" (known as "orçamento" in Portuguese). These budgets are associated with a "cadastre", where each cadastre can have multiple budgets. Below, you can find the components involve ...

Returning a Response in HapiJS Routes from Incoming Requests

Currently, I am facing an issue with the request module where I am able to successfully make a request and receive a response. However, I am struggling to figure out how to pass this response back to my route in order to return it to my client. Here is th ...

How can I stop the countdown when I receive input in Python?

Description: Currently, I have implemented input and countdown functionalities simultaneously. However, my goal is to achieve the following scenarios: If no input is provided during the countdown, another function should be executed after the countdown co ...

Learning how to effectively incorporate two matSuffix mat-icons into an input field

I'm currently experiencing an issue where I need to add a cancel icon in the same line as the input field. The cancel icon should only be visible after some input has been entered. image description here Here's the code I've been working on ...

Troubleshooting: 404 Error When Trying to Send Email with AJAX in Wordpress

In the process of creating a unique theme, I encountered an interesting challenge on my contact page. I wanted to implement an AJAX function that would allow me to send emails directly from the page itself. After conducting some research, I managed to find ...

Zero's JSON Journey

When I make an HTTP request to a JSON server and store the value in a variable, using console.log() displays all the information from the JSON. However, when I try to use interpolation to display this information in the template, it throws the following er ...

Applying Tailwind styles to dynamically inserted child nodes within a parent div

Currently, I am in the process of transitioning my website stacktips.com from using Bootstrap to Tailwind CSS. While initially, it seemed like a simple task and I was able to replace all the static HTML with tailwind classes successfully. However, now I ha ...

Sharing data between two Angular 2 component TypeScript files

I'm facing a scenario where I have two components that are not directly related as parent and child, but I need to transfer a value from component A to component B. For example: In src/abc/cde/uij/componentA.ts, there is a variable CustomerId = "sss ...

Error: The property 'postID' can not be read because it is undefined

I'm new to programming and I am working on creating a news/forum site as a practice project. I have set up a route /post/postID/postTitle to view individual posts. Initially, when I used only :postID, it worked fine. But after adding :postTitle, whene ...

Navigating Between Modules Using ui-router in Angular: Best Practices

One of the great things about working with Angular is the ability to divide functionality into modules to support multiple applications. For example, if I have two apps that could both benefit from the same "User" module, I can simply include that module i ...

Include the array in the 'content' property of the CSS using Jquery

I need help formatting data in CSS. The code I have is as follows: if (ext){ switch (ext.toLowerCase()) { case 'doc': pos = 'doc'; break; case 'bmp': pos = 'bmp'; break; ...

A guide on retrieving real-time data from PHP using Ajax

Being new to Ajax, I am struggling to grasp how to retrieve changing variable values from php. Below is the code snippet that I have been working on: <?php $pfstatetext = get_mypfstate(); $cpuusage= cpu_usage(); ?> <div id="show"> <c ...

Get rid of the spaces in web scraping <tr> tags using Node.js

I've encountered a problem that goes beyond my current knowledge. I'm attempting to web-scrape a specific webpage, targeting the <tr> element in nodejs. Although I can successfully retrieve the content, it seems that the format is not as cl ...

Validating forms using TypeScript in a Vue.js application with the Vuetify

Currently, I am attempting to utilize Vue.js in conjunction with TypeScript. My goal is to create a basic form with some validation but I keep encountering errors within Visual Studio Code. The initial errors stem from my validate function: validate(): v ...

How to Utilize AngularJS to Interact with Play 2 REST API Despite CORS Challenges

I am currently working on an AngularJS application that interacts with a REST API built using Play Framework 2.2.0. One issue I've encountered involves cross-domain ajax calls, since the Angular and Play applications are not hosted on the same domain ...

Master the Art of Scrollbar Control in Angular!

I am currently developing a chat web application that functions similar to gchat. One of the key features I'm trying to implement is an alert notification when the scrollbar is in the middle of the div, indicating a new message. If the scrollbar is at ...

Exploring the bounds of self-invocation functions in JavaScript

Have you ever wondered why self-invocation functions inside another function in JavaScript don't inherit the scope of the outer function? var prop = "global"; var hash = { prop: "hash prop", foo: function(){ console.log(this.prop); ...