Coder Social home page Coder Social logo

Comments (4)

szchenghuang avatar szchenghuang commented on June 1, 2024 1

You are handling it fine. The caller is notified with the 'canceled' string. If it becomes a bit superfluous when it throws, you can make a string comparison in the catch clause and simply ignore the case with a noop.

from debounce-async.

bradley-varol avatar bradley-varol commented on June 1, 2024 1

I have a use case where I don't want to handle errors with catch() so I'd love an argument to allow me to disable this feature. I'd like to be able to essentially force shouldCancel to always be false.

from debounce-async.

szchenghuang avatar szchenghuang commented on June 1, 2024

It rejects in order to tell which are ignored, and to notify the caller. If it resolves with nothing for the ignored, the caller needs to make a comparison between the resolved values in order to tell which is ignored and which is not. It becomes trickier.

from debounce-async.

roemhildtg avatar roemhildtg commented on June 1, 2024

Okay, I think that makes sense, maybe I'm just handling it incorrectly. Here's my situation:

const debouncedAjax = debounce((params) => {
    return $.ajax('/api/items', params);
});

// else where in code
// function called whenever params change...this is debounced so if multiple params change quickly
// we don't call the ajax function each time
const result = debouncedAjax(params);

result.then(() => { alert('success!'); })
    .catch(e => { alert(e.message); }); // alerts "cancelled" every time....how do I prevent this?

from debounce-async.

Related Issues (4)

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.