-
-
Notifications
You must be signed in to change notification settings - Fork 168
Adding progress #56
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
Adding progress #56
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thread.off('progress')
approach can be improved.
src/job.js
Outdated
@@ -35,6 +35,8 @@ export default class Job extends EventEmitter { | |||
|
|||
executeOn(thread) { | |||
thread | |||
.off('progress') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be better to remove the progress listener after being done, especially for garbage collection. Could do that using thread.promise().then(() => thread.off('progress'), () => thread.off('progress'))
.
But the thread.off('progress')
behavior might cause side effects, since it does not only remove the listeners we set here in the job, but all others as well. thread.removeListener('progress', this.onProgress)
would be preferable, but we would also need to move this.emit('progress', e)
to onProgress
and bind it beforehand.
src/job.js
Outdated
@@ -35,6 +35,8 @@ export default class Job extends EventEmitter { | |||
|
|||
executeOn(thread) { | |||
thread | |||
.off('progress') | |||
.on('progress', (e) => {this.emit('progress', e)} ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should use either arrow function or .bind()
consistently here across all .on()
/.once()
Hey @mmcardle. Thanks for your PR! The idea is to make the job propagate the thread's I reviewed the changes and identified an edge case. Nothing too serious, but might be worth looking into :) |
thanks @andywer I shall give it a look |
@andywer I have pushed a few changes, trying to get my head around the event emitter framework. Also updated the PR text so its clear what I am trying to achieve. Thanks |
Hey @mmcardle. I applied an easy fix and I hope that does the trick. Have a look at it and let's see if the tests are green, since I just edited here on github... Thanks for your efforts so far :) That event emitter / callback stuff can be really nasty. That's why I am already planning for a version 1.0 built on top of observables 😉 |
Hi @andywer Thats looks good, it functions correctly in my application, tests are red though, ill see if i can see the issue. |
@andywer That last commit fixed the tests, do you want me to update README/CHANGELOG with changes? |
Neat! 😊 Yeah, you can add a section Is there anything to update in the readme? Planning to merge & publish this today or tomorrow. |
I am actually quite ok with the PR. There is just one thing I'd like to see: An additional test case for FYI: Just opened another PR (#58) that adds support for async thread functions, in case you are interested. Promises are nicer than callbacks :) |
I shall take a look at adding that test, and yes promises all the way! |
@andywer updated |
Ahh, did you still want to update the docs? Now I merged it already... |
Ah no thats great! thanks for all your help! |
Published as v0.8.0 |
@andywer just checking the npm build updated correctly? i have a few diffs between a local build and the one downloaded from npm
|
Yeah, that does look fishy. My local transpiled files look fine, though: Job.prototype.executeOn = function executeOn(thread) {
var _this2 = this,
_thread$on$once$once$,
_thread$on$once$once;
var onProgress = function onProgress() {
for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = arguments[_key3];
}
return _this2.emit.apply(_this2, ['progress'].concat(args));
};
var onMessage = function onMessage() {
for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
args[_key4] = arguments[_key4];
}
_this2.emit.apply(_this2, ['done'].concat(args));
thread.removeListener('progress', onProgress);
};
var onError = function onError() {
for (var _len5 = arguments.length, args = Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
args[_key5] = arguments[_key5];
}
_this2.emit.apply(_this2, ['error'].concat(args));
thread.removeListener('progress', onProgress);
};
(_thread$on$once$once$ = (_thread$on$once$once = thread.on('progress', onProgress).once('message', onMessage).once('error', onError)).run.apply(_thread$on$once$once, this.runArgs)).send.apply(_thread$on$once$once$, this.sendArgs);
this.thread = thread;
this.emit('threadChanged');
return this;
}; Very strange. I will have a look at that :-/ |
PS: Thanks for pointing out! |
Observation 1: Observation 2: So I think I will just re-publish as 0.8.1 and it should be fine. But I really can't tell how something like this is even possible, esp. since there is the |
Re-published as |
@andywer that has fixed it, thanks! |
The purpose of this PR is to allow progress reports from jobs when they are executed and also when they are submitted to a Pool.