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

How to stop a task while running? #2135

Closed
niftylettuce opened this issue Mar 7, 2018 · 6 comments
Closed

How to stop a task while running? #2135

niftylettuce opened this issue Mar 7, 2018 · 6 comments

Comments

@niftylettuce
Copy link

Is there an easy way to end a gulp task while running?

e.g. you save a.js during a gulp watch, it's still re-compiling and you make changes and save a.js again before the task to re-compile it finishes -- the first task instance should be cancelled and the second should complete only

@stephenlacy
Copy link
Contributor

Plugins manage the file stream manipulation outside of gulp's control.
If gulp were to emit an 'end' event to the stream, the library compiling the file would need to know how to handle it, and that library would be responsible for pausing compilation.

@yocontra
Copy link
Member

yocontra commented Mar 7, 2018

@phated Possible with the new task orchestration system? Canceling would noop for callbacks, call .end() early for streams, or do promise cancellation. I think that would be a good addition if we don't have it already, or at least the ability to grab the return values of tasks that are executing (stream or promise).

@niftylettuce If you want a potential workaround you can assign the stream in your task to a hoisted variable and do if (lastStream) lastStream.end() before you call your task from watch. This is assuming processing on a.js hasn't already started a big synchronous transformation like uglify, which there is no way to abort.

@phated
Copy link
Member

phated commented Mar 7, 2018

Do you realize you are asking me to kill an already running function? No, JS doesn't work like that.

@phated phated closed this as completed Mar 7, 2018
@niftylettuce
Copy link
Author

Promise cancellation prob best option https://github.com/sindresorhus/p-cancelable

@phated
Copy link
Member

phated commented Mar 7, 2018

This has nothing to do with core and won't be added.

@niftylettuce
Copy link
Author

Agreed @phated this is totally custom and outside of scope of core. Thank you!

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

No branches or pull requests

4 participants