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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:50:16+00:00 2026-06-07T15:50:16+00:00

I have a function matcher which is called every time a keyup event is

  • 0

I have a function matcher which is called every time a keyup event is sent.

This function belongs to a module which look like this (1).
what if another call is done before the fetching is completed?
How can I solve this problem in this module (1)?


(1)

(function ($, UserCollection) {

    var userCollection;

    var matcher = function (request, response) {
        if (!userCollection) {
            userCollection = new UserCollection();
            userCollection.fetch();
        } else {
            isMatched(request, response);
        }
    };

    return matcher;
}(jquery, UserCollection));
  • 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-07T15:50:19+00:00Added an answer on June 7, 2026 at 3:50 pm

    I’ll take a different, probably overkill, approach and use the jqXHR object returned by collection.fetch.

    var Matcher=(function($,UserCollection) {
    
        var xhr=null, userCollection=null;
    
        // matching against a defined ID for testing purpose
        function isMatched(id) {
            return userCollection.get(id);
        }
    
        // the request would be an ID in my example,
        // and the callback is the function invoked when the collection is fetched
        function matcher(request, callback) {
            if (!xhr) {
                userCollection = new UserCollection();
    
                // fetch returns a handy xhr object used for the deferred
                xhr=userCollection.fetch(); 
            }
    
            xhr.then(function() {
                callback(isMatched(request));
            });
        }       
    
        return matcher;
    
    })(jQuery, UserCollection);
    

    If the xhr is already resolved, the callback is immediately invoked, if not, it will be when the request completes : see jQuery.Deferred for more info.

    And you would use it as

    Matcher(1,console.log);
    Matcher(2,console.log);
    

    And a Fiddle http://jsfiddle.net/EWSAV/1/

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

Sidebar

Related Questions

I have function like this: function ypg_delete_img($id, $img) { $q = $this->ypg_get_one($id); $imgs =
I have function like this: function gi_insert() { if(!IS_AJAX){ $this->load->library('form_validation'); $this->form_validation->set_rules('name', 'Naslov', 'trim|required|strip_tags'); $this->form_validation->set_rules('body',
I have one function which is called on list item Click and list items
I have a function that uses Pattern#compile and a Matcher to search a list
I have function some_func_1 which will create an object of type some_type and will
Sorry for the novice question! I have a table called cities in which I
Right now I have a function which takes my uploaded file, checks the extension,
I have a function in Java which I need to convert into php. It
A postgresql 9.1 DB writes data which is sent automatically from a machine. This
I have a global variable which is an instance of a class. This class

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.