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
Progress reporting #33
Comments
What kind of progress are you interested in? Per-file or percentage? Or rather, what do you need it for? |
I need it for UI. Next, this is a matter of what is easier to implement:
As writing this, I thought, maybe it is better to do it at
|
It looks like |
@jamestalmage I think progress events can be throttled with some configurable or reasonable delay. |
Seems to be doable with |
Or with promise-concurrent ;) |
Are we waiting for some action to move forward here? |
@YurySolovyov If you want to, please create a separate issue/PR for limiting parallel copying. Otherwise, things get too messy. About reporting: Some approaches popped into my head:
const c = cpy(files, destination);
c.on('progress', onProgress);
c.then(() => console.log('done')); |
@schnittstabil I thought about option 2 mostly because it does not break API and allows to detect if we don't need progress reporting, so users won't pay for the thing they don't use. |
@YurySolovyov I also prefer the second one, easy to switch to a promise-based solution in the future. |
Or do a breaking change and use Observables instead. |
@schnittstabil My concern is mainly about if this module is right place (I mean maybe |
@YurySolovyov EDIT: Aww, the sizes aren't known by |
@SamVerschueren I would prefer not making a breaking change at this point and while Observables are nice, the main use-case is just executing and knowing when it's done. Promises also have the benefit of being part of the language and it's common knowledge. Observables not so much. |
I like |
@sindresorhus close to zero if no listener attached, and somewhat proportional to frequency of data events otherwise I guess. |
@schnittstabil Why do you prefer @SamVerschueren Which one do you prefer if we leave out Observables? |
Definitely |
Yeah, maybe we should put size reporting into |
👍 |
You mean that I should proceed with a PR for |
I'm ok with the idea, but would like to hear from @schnittstabil first. How do you plan to expose the sizes in |
@sindresorhus not sure there is much options here: need to do stat call + count bytes on stream data events, or inspect bytesWritten with some interval, maybe add some throttling, does that sound ok? |
Mainly because (cpy(…)) instanceof Promise // => false Thinking about it, a fourth solution, using delegation comes to my mind: const c = cpy(files, destination);
c instanceof Promise // => true
c.events instanceof EventEmitter // => true
I'm also fine with By the way, I don't think there is real benefit for |
I started with |
@YurySolovyov In the meantime, I see a real benefit of EventEmitters: cpy.on('start', filename => console.log(`copying of '${filename}' started`));
…
cpy.on('end', filename => console.log(`copying of '${filename}' ended`)); |
@schnittstabil so you purpose to embed EE into promise returned by |
No, returned by Something like: module.exports = function (src, dest, opts) {
// …
var events = new EventEmitter()
var p = globby(src, opts)
// …
// use events.emit or events in some way
//...;
p.events = events;
return p;
} |
I guess the something similar should be done at |
@YurySolovyov Feel free to investigate what |
@schnittstabil one thing that bothers me a little with events embedding is that it mutates promise object which may lead to performance decrease. Though it is not yet known if it is the case, but it might be. |
@schnittstabil We don't have to inherit the EventEmitter, we just use it as a mixin on the Promise. That way we get events, but also the proper inheritance. With ES2015, we could even cheat it by using |
The mutation itself? Very, very unlikely - I can't image any problem. Creating an EE object and emitting events, especially if there's no subscriber? |
Now we need to consume info from |
Any interested in finishing this? No worries if not. Just thought I would ask :) |
Will try to look into it this weekend. |
Any ideas about shape of the progress object? {
completedFiles: Number,
totalFiles: Number,
completedSize: Number,
totalSize: Number
} Thing is that getting total size might add a delay proportional to number of files to copy. |
Looks good, but I don't think |
Hi. I thought I'd take a shot at this. Let me know if you want me to change anything. |
It would be nice to have an ability to hook into underlying stream(s) to have this. This might be more tricky to get right WRT multiple files, though. Opening issue first to discuss.
The text was updated successfully, but these errors were encountered: