Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

How do you cancel job1 completely before its timeout value occur? #847

Closed
gertcuykens opened this issue Dec 27, 2014 · 9 comments
Closed

Comments

@gertcuykens
Copy link

https://www.polymer-project.org/docs/polymer/polymer.html#job

this.responseChanged = function() {
  this.job('job1', function() { // first arg is the name of the "job"
    this.fire('done');
  }, 500);
}
@gertcuykens gertcuykens changed the title https://www.polymer-project.org/docs/polymer/polymer.html#job How do you cancel job1 completely before its time out value occur? Dec 27, 2014
@gertcuykens gertcuykens changed the title How do you cancel job1 completely before its time out value occur? How do you cancel job1 completely before its timeout value occur? Dec 27, 2014
@ebidel
Copy link
Contributor

ebidel commented Dec 27, 2014

job() is for debouncing. Presumably you want whatever you're wrapping to be called at least once. If you want a cancelable call, try async() which can be canceled using cancelAsync():

https://github.com/Polymer/polymer/blob/87b3815812aaa9f956f044e74d43460b1babee5f/src/instance/utils.js#L53

We need to document this method: #848

@gertcuykens
Copy link
Author

Let say you have a hover in and hover out where the hover toaster get a delay before it disappears after a hover out. But when you hover back in quick enough you need to cancel that job of disappearing.

The thing about async() is that it doesn't cancel itself when you hover in out in multiple times before the timeout like job() does?

@gertcuykens
Copy link
Author

Currently I do it like this

            in: function (e){
                this.cancel=true
                document.querySelector('my-hover').fire('my-hover-in', {'title': title})
            },

            out: function (e){
                this.cancel=false
                this.job('myJob', function() {
                    if (this.cancel) return 0
                    document.querySelector('my-hover').fire('my-hover-out')
                }, 500);
            },

But this would be nicer

            in: function (e){
                this.jobCancel('myJob')
                document.querySelector('my-hover').fire('my-hover-in', {'title': title})
            },

            out: function (e){
                this.job('myJob', function() {
                    document.querySelector('my-hover').fire('my-hover-out')
                }, 500);
            },

@arthurevans
Copy link

A little code poking reveals an alternate way of invoking job, using a job handle instead of a string. You can use the handle to stop the job, like this:

this.myjob = this.job(this.myjob, function);
this.myjob.stop();

Big caveat -- this syntax may be deprecated:

https://github.com/Polymer/polymer/blob/87b3815812aaa9f956f044e74d43460b1babee5f/src/instance/base.js#L52
https://github.com/Polymer/polymer/blob/master/src/lib/job.js#L41

It would be pretty trivial to add a cancelJob method. What say you, @sjmiles ?

@gertcuykens
Copy link
Author

Great thanks, I would never tought of that

PS Actually I would deprecate this part haha :)

var n = '___' + job;
this[n] = Polymer.job.call(this, this[n], callback, wait);

not the following part because it is nicer and does not mess with polymer internals.

return Polymer.job.call(this, job, callback, wait);

@ebidel
Copy link
Contributor

ebidel commented Apr 6, 2015

This issue has gone stale. Marking as obsolete.

@ebidel ebidel closed this as completed Apr 6, 2015
@ebidel ebidel added the obsolete label Apr 6, 2015
@gertcuykens
Copy link
Author

I am happy the github issues are getting cleaned up. I know you all have things to do and I also know allot of them are invalid, but still every open issue is a frustrated user and every polymer team member should know that even if it is not there fault.

@arthurevans
Copy link

Talked to core folks. I'm going to re-open and move this to Polymer/polymer as an 0.8 feature request.

@arthurevans
Copy link

This issue was moved to Polymer/polymer#1374

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

No branches or pull requests

3 participants