GithubHelp home page GithubHelp logo

Comments (3)

scottgonzalez avatar scottgonzalez commented on May 14, 2024

Requests should not block. What you probably want is throttling that will put concurrent requests on hold and then respond with the cached response when the first request completes.

from amplify.

brianmhunt avatar brianmhunt commented on May 14, 2024

Sorry; "block" was a misleading word. The idea is that the request is not being 'blocked' in the async sense, but rather the request is added to a queue rather than submitting multiple duplicate AJAX requests. Here's some rough code:

function request(resource_name, callback) {
   this_request = some_lookup_of_requests.get(resource_name);

   if this_request.is_outstanding(resource_name) {
      // by outstanding - the request has been made, and a response not
      // yet received

     subscribe(this_request, callback); 
     // when the ajax returns, the results are published
   } else {
      amplify.request(resource_name, function (...) { 
        this_request.no_longer_outstanding();
        // make sure that subsequent requests do not subscribe when
        // no ajax request is outstanding

        callback(...); // tell the caller

        publish(this_request, ...); // notify any subscribers
      });
   }
}

This is not really caching in the traditional sense; it may be better to describe it as a subscriber/publisher alternative to multiple concurrent requests.

I am not sure if this is something amplify.js would want - but since it reduces the need for developers to think about the need for multiple concurrent requests I tend to think it is helpful - but in any case I hope the above clarifies what I had intended.

Plus it's fun. :)

Cheers.

from amplify.

mariusfilipowski avatar mariusfilipowski commented on May 14, 2024

I am facing the same problem. It would be very cool to have such a mechanisms. Or how it be implemented on our own? Any hints?

from amplify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.