nodejitsu / nexpect

spawn and control child processes in node.js with ease
http://github.com/nodejitsu/nexpect
Other
290 stars 37 forks source link

Add ability for wait function to take a callback #23

Closed brandon-fryslie closed 9 years ago

brandon-fryslie commented 9 years ago

Here is the background of why I made this change and what it enables. I wrote a script to start a series of services that must start serially, some of which take arguments or environment variables from the output of other services. I also wanted to be able to start one, some, or all of the services easily.

I was able to write something like that in about 20 lines using a promise library and 'wait' with a callback to resolve the promise. It turned out to be incredibly powerful. Here is a gist of some of the relevant parts of my script: https://gist.github.com/brandon-fryslie/802e51b1ec385b3eb79c

I think it's a useful feature that enables some really cool ideas. Thoughts?

sam-github commented 9 years ago

I don't have any real comments, no time to read your giss, I'll take your word for it that it was useful.

But I think I'd be remiss if I merged something in with no unit tests. So, make sure current tests pass, and this feature is tested, and I'll merge.

brandon-fryslie commented 9 years ago

Thank you. I'll submit some tests soon.

brandon-fryslie commented 9 years ago

I have included 2 tests. One asserts that the callback is run if the output matches the 'wait' string, one asserts that the callback is not called if the output does not match the 'wait' string.

sam-github commented 9 years ago

Thank you!