Use Case:


There may be circumstances where you would like to use multiFetch but require more control over its execution, rather than simply implementing multiFetch in its default linear fashion (which does not allow registering and fetching while a fetch is in progress).


For example, if an end user clicks on a particular part of a page (e.g. Men's Fashion), but then quickly changes their mind and clicks on a different area (e.g., Women's Fashion) that executes a request for different types of recommendations, the default multiFetch mechanism would generate an error about the original operation still being in progress.


One solution to this is to use the allowLazyRegister config along with multiFetch. This will make sure that all the fetches execute, but it only executes the later fetches after the earlier ones complete. As a result, when a user toggles rapidly between options, it could lead to a situation where new fetches get significantly delayed waiting on earlier fetches to complete.


This is the kind of situation where `abortActiveRequests` is useful. With the `abortActiveRequests` feature, the original `register` and `fetch` functions associated with the initial click would get aborted so that the new `register` and `fetch` operations associated with the second click may be accepted and executed without erroring out.


How to Use `abortActiveRequests`:


Add the special parameter `abortActiveRequests` in $p("register") and $p("fetch") to abort/cancel requests in progress if any exist. The cancelled `register` or `fetch` function(s) will no longer work (including any rendering functions in the callbacks that might rely on those aborted functions), but new `register` and `fetch` functions will be accepted. Technically speaking, it should suffice to simply us abortActiveRequests in the very first register call of the sequence of register calls + fetch call; however, it may be safer to include it in all calls if you are not sure about the order of execution.


Example code:

$p("register",{
    max: 5,
    widget: "new_news",
    opts: {maxAgeInSeconds: 60*60*24},
    callback: function(resp){
        console.log(resp)
    },
    abortActiveRequests: true
})


$p('fetch', {
    abortActiveRequests: true
})