Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation pipeline should support cancelation #217

Closed
Daniel-Glucksman opened this issue Sep 27, 2015 · 10 comments
Closed

Navigation pipeline should support cancelation #217

Daniel-Glucksman opened this issue Sep 27, 2015 · 10 comments

Comments

@Daniel-Glucksman
Copy link

one of my viewmodels activate function takes a while to complete around 15 seconds, if the route is mid activation and then I click another route, the router will wait for the old one to finish activating before proceeding to the new one which means that you're essentially stuck for those 15 seconds. Is there a way for it to cancel the old activation and proceed to the new one.

@EisenbergEffect
Copy link
Contributor

There is no notion of "cancellation" in promises at this point in time, though I have heard talk that the API may be improved to include that at some point in the future. But, as things are, there's nothing that Aurelia can really do to handle this automatically.

My recommendation would be, for this case, to not return a promise from your activate method. Instead, fix up the view for that screen so that it shows its own internal loading indicator until the data is loaded. That way the router is free to navigate away even if the data hasn't completed loading.

@Daniel-Glucksman
Copy link
Author

Is there a way that Aurelia that if given a promise can wrap that promise in another container which can allow for an early reject. So let's say PromiseWrapper would take a promise and have a method called EarlyReject which would reject the promise mid way.

@bryanrsmith bryanrsmith reopened this Sep 27, 2015
@bryanrsmith
Copy link
Contributor

I'm going to leave this open because I think we do need to handle cancelation at some point, and we don't have an issue tracking it yet.

@bryanrsmith bryanrsmith changed the title Changing routes mid activation Navigation pipeline should support cancelation Sep 27, 2015
@mttmccb
Copy link

mttmccb commented Jan 29, 2017

While not part of promises bluebird has cancellation http://bluebirdjs.com/docs/api/cancellation.html

@Alexander-Taran
Copy link
Contributor

Thou shalt not force the user to wait 15 seconds for activate to finish.
Long running loads should have their own spinners in the view.

I'd close this

@EisenbergEffect
Copy link
Contributor

Let's keep it for now, though I don't think we'd do it outside of overhauling the router in some future version.

@fkleuver
Copy link
Member

With regards to overhauling the router in a future version, I'm adding a reference to a somewhat related issue. It's about rendering a parent route's viewmodel before a child route's activate promise has resolved.

@Alexander-Taran
Copy link
Contributor

Might I add that whole middleware pipeline as in asp.net core and koa looks so appealing

@davismj
Copy link
Member

davismj commented Mar 15, 2018

I'm honestly with Alex here. If you want to support cancellation, you can easily do this by wrapping a promise.

activate() {
  return new Promise((resolve, reject) => {
    this.doMyReallyLongTimeThing().then(resolve);
    setTimeout(reject, 15000);
  }
}

@EisenbergEffect I'd vote to close. Your thoughts?

@EisenbergEffect
Copy link
Contributor

EisenbergEffect commented Mar 15, 2018

I'll close. I believe that this is the recommended way to handle cancellation of promises actually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants