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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:13:09+00:00 2026-05-25T22:13:09+00:00

Similar to the promises pattern I’m looking for an event pattern that avoids needing

  • 0

Similar to the promises pattern I’m looking for an event pattern that avoids needing to pollute objects with addEventListener/etc methods, I want to be able to return an object, that can be cancelled as well as ‘resolved’ multiple times.

For example, I may write a method that returns an ‘interval’ object, something like this:

var ticker = createTicker(1000);
var subscription = ticker.then(function() { console.log('tick') });
... later on ...
subscription.cancel();

The key differences here being, similar to a promise the events are standardized, so that I can subscribe without needing to know the event name, however unlike a promise, the “completion” can happen multiple times, and may even be cancelled (this would be equiv of removeEventListener).

I’m interested to see if this is legal with promises, such that the progress handler could be used for multiple callbacks, and the complete handler never used, but more importantly, that there is a concept of unsubscribing from a promise.

If this isn’t the case, and promises are specialized to this scenario, is there a standardized pattern for doing what I described?

  • 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-05-25T22:13:09+00:00Added an answer on May 25, 2026 at 10:13 pm

    The ability to cancel can be added to a promise implementation, without breaking the main paradigm of having single-fire success/failure callbacks.

    In fact, jQuery already has cancellation for the promise instances that it returns from jQuery.ajax calls:

    For backward compatibility with XMLHttpRequest, a jqXHR object will
    expose the following properties and methods:

    • readyState
    • status
    • statusText
    • responseXML and/or responseText when the underlying request responded with xml and/or text, respectively
    • setRequestHeader(name, value) which departs from the standard by replacing the old value with the new one rather than concatenating the new value to the old one
    • getAllResponseHeaders()
    • getResponseHeader()
    • abort()

    You could write a setTimeout wrapper that exposes a promise interface along with an additional cancel method.

    However, once you get into the multi-fire territory, I think that is not what promises are intended for. You would have to define a lot of rules and exceptions around how multiple firing will play out alongside regular promise functionality. It doesn’t make a lot of sense to me to use promises that way.


    Update (based on discussion in comments):

    Here’s a sample implementation of a promise “proxy” that allows aborting further relaying of the done/fail callbacks:

    http://jsfiddle.net/atesgoral/qvtqu/

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

Sidebar

Related Questions

Similar to the one here on StackOverFlow, I would be needing to implement a
Similar to List<> OrderBy Alphabetical Order , we want to sort by one element,
I'm developing an app that is vaguely similar to twitter, in that it allows
I've read that qsort is just a generic sort, with no promises about implementation.
Looking at examples about socket programming, we can see that some people use AF_INET
I have just stumbled upon Bad Behavior - a plugin for PHP that promises
Similar question here but this is slightly different... I have two tables that I
Similar to WCF Self Hosting. Is there a way to create a website that
Similar to This Question using linq to SQL , but I don't want to
Similar to this question I have a small groovy test script that basically uses

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.