grunt icon indicating copy to clipboard operation
grunt copied to clipboard

Pass callback to grunt.task.run

Open donaldpipowitch opened this issue 10 years ago • 42 comments

grunt.task.run runs a task after another has finished. However I need to run a task from within a task and process things after the other task has finished. An API like this would be beautiful:

var done = this.async();
grunt.task.run('some-task', function() {
  // do things after 'some-task' finished
  done();
});

I couldn't find a way to do that with the current API.

EDIT: What I currently do to solve this problem. I use another internal task which runs before/after my some-task. This internal task is only needed to set some dynamic config and shouldn't be called manually. Usage looks like this:

grunt.task.run('internal-task', 'some-task');
// or
grunt.task.run('some-task', 'internal-task');

donaldpipowitch avatar Jul 24 '14 14:07 donaldpipowitch

+1

monolithed avatar Aug 14 '14 12:08 monolithed

FWIW, something similar is planned for v0.5. See #542

Florian-R avatar Aug 14 '14 15:08 Florian-R

+1

madhums avatar Aug 22 '14 13:08 madhums

+1

digitalmaster avatar Sep 01 '14 21:09 digitalmaster

+1

bzwheeler avatar Sep 06 '14 02:09 bzwheeler

:+1:

//cc @cowboy

hemanth avatar Sep 17 '14 03:09 hemanth

+1

hartatovich avatar Sep 20 '14 00:09 hartatovich

+1

nikolaygit avatar Sep 20 '14 20:09 nikolaygit

+1

tecfu avatar Sep 21 '14 13:09 tecfu

+1

s2young avatar Sep 29 '14 19:09 s2young

:+1: +1

bluecurio avatar Oct 10 '14 17:10 bluecurio

+1

beeplove avatar Oct 16 '14 20:10 beeplove

Yes, please. Gimme two.

z0r1k avatar Nov 10 '14 16:11 z0r1k

+1

soundstep avatar Nov 12 '14 09:11 soundstep

+1

abelnation avatar Nov 14 '14 07:11 abelnation

+1

gregjacobs avatar Nov 20 '14 18:11 gregjacobs

+!

matthewstokeley avatar Dec 03 '14 18:12 matthewstokeley

Please just hit "Subscribe" rather than reply with "+1" which spams everyone following the thread, thanks.

aehlke avatar Dec 03 '14 18:12 aehlke

+1

YuhangGe avatar Dec 08 '14 13:12 YuhangGe

+1

aaccurso avatar Jan 07 '15 13:01 aaccurso

+1

elliot-a avatar Jan 08 '15 14:01 elliot-a

there should also be an argument with the task completion status code in this "finalize callback" and a possitibility to to avoid interruption of the task flow;

grunt.task.run('some-task', function (status) {
  console.log('some-task completed with status: ' + status);

  return true; // force continue
});

kodmax avatar Jan 13 '15 10:01 kodmax

+1

excitepv avatar Jan 14 '15 06:01 excitepv

+1

perry-mitchell avatar Jan 29 '15 14:01 perry-mitchell

Please just click "Subscribe" on the right instead of replying to +1 (which pings all subscribers), thanks.

aehlke avatar Jan 29 '15 15:01 aehlke

I just now finished making grunt-anon-tasks to solve this problem.

grunt.task
  .run("some-task")
  .then(function () {
    // do stuff after "some-task" completes, but before "other-task" begins
  })
  .run("other-task")

Check out the repo to learn more.

aleclarson avatar Mar 10 '15 12:03 aleclarson

+1

nadav-dav avatar Jun 11 '15 08:06 nadav-dav

+1

zsxsoft avatar Jun 13 '15 08:06 zsxsoft

:+1:

ghost avatar Jul 10 '15 18:07 ghost

+1

amitnabarro avatar Sep 02 '15 10:09 amitnabarro