Skip to main content
deleted 44 characters in body
Source Link
Ian Newson
  • 882
  • 5
  • 14

Is there a name for this pattern? I've written this kind of thing a few times in JavaScript and recently found myself writing it in C#. Thing is, I expect this has already been implemented in a library somewhere I didn't know what to look for.

In pseudo code it's something like this:

var referenceToPreviousRequest = null;
if (null != referenceToPreviousRequest) {
    referenceToPreviousRequest.cancel();
}
    
referenceToPreviousRequest = setTimeout(function() {
    //The thing I ultimately want to do
}, 1000 /*The delay after the last request*/);

Typically I use this kind of code in client side JavaScript, for delaying an AJAX request until a certain amount of time after the last user input, e.g. searching.

Is there a name for this pattern? I've written this kind of thing a few times in JavaScript and recently found myself writing it in C#. Thing is, I expect this has already been implemented in a library somewhere I didn't know what to look for.

In pseudo code it's something like this:

var referenceToPreviousRequest = null;
if (null != referenceToPreviousRequest) {
    referenceToPreviousRequest.cancel();
}
    
referenceToPreviousRequest = setTimeout(function() {
    //The thing I ultimately want to do
}, 1000 /*The delay after the last request*/);

Typically I use this kind of code in client side JavaScript, for delaying an AJAX request until a certain amount of time after the last user input, e.g. searching.

Is there a name for this pattern? I've written this kind of thing a few times in JavaScript and recently found myself writing it in C#. Thing is, I expect this has already been implemented in a library somewhere I didn't know what to look for.

In pseudo code it's something like this:

if (null != referenceToPreviousRequest) {
    referenceToPreviousRequest.cancel();
}
    
referenceToPreviousRequest = setTimeout(function() {
    //The thing I ultimately want to do
}, 1000 /*The delay after the last request*/);

Typically I use this kind of code in client side JavaScript, for delaying an AJAX request until a certain amount of time after the last user input, e.g. searching.

deleted 11 characters in body
Source Link
CodesInChaos
  • 5.8k
  • 4
  • 22
  • 27

Is there a name for this pattern? I've written this kind of thing a few times in JavaScript and recently found myself writing it in C#. Thing is, I expect this has already been implemented in a library somewhere I didn't know what to look for.

In pseudo code it's something like this:

    var referenceToPreviousRequest = null;
    if (null != referenceToPreviousRequest) {
    referenceToPreviousRequest.cancel();
    }
    
referenceToPreviousRequest = setTimeout(function() {
    //The thing I ultimately want to do
}, 1000 /*The delay after the last request*/);

Typically I use this kind of code in client side JavaScript, for delaying an AJAX request until a certain amount of time after the last user input, e.g. searching.

Is there a name for this pattern? I've written this kind of thing a few times in JavaScript and recently found myself writing it in C#. Thing is, I expect this has already been implemented in a library somewhere I didn't know what to look for.

In pseudo code it's something like this:

    var referenceToPreviousRequest = null;
    if (null != referenceToPreviousRequest) {
    referenceToPreviousRequest.cancel();
    }
    
referenceToPreviousRequest = setTimeout(function() {
//The thing I ultimately want to do
}, 1000/*The delay after the last request*/);

Typically I use this kind of code in client side JavaScript, for delaying an AJAX request until a certain amount of time after the last user input, e.g. searching.

Is there a name for this pattern? I've written this kind of thing a few times in JavaScript and recently found myself writing it in C#. Thing is, I expect this has already been implemented in a library somewhere I didn't know what to look for.

In pseudo code it's something like this:

var referenceToPreviousRequest = null;
if (null != referenceToPreviousRequest) {
    referenceToPreviousRequest.cancel();
}
    
referenceToPreviousRequest = setTimeout(function() {
    //The thing I ultimately want to do
}, 1000 /*The delay after the last request*/);

Typically I use this kind of code in client side JavaScript, for delaying an AJAX request until a certain amount of time after the last user input, e.g. searching.

Source Link
Ian Newson
  • 882
  • 5
  • 14

What is this pattern called? Run finally?

Is there a name for this pattern? I've written this kind of thing a few times in JavaScript and recently found myself writing it in C#. Thing is, I expect this has already been implemented in a library somewhere I didn't know what to look for.

In pseudo code it's something like this:

    var referenceToPreviousRequest = null;
    if (null != referenceToPreviousRequest) {
    referenceToPreviousRequest.cancel();
    }
    
referenceToPreviousRequest = setTimeout(function() {
//The thing I ultimately want to do
}, 1000/*The delay after the last request*/);

Typically I use this kind of code in client side JavaScript, for delaying an AJAX request until a certain amount of time after the last user input, e.g. searching.