survey icon indicating copy to clipboard operation
survey copied to clipboard

Add a timeout feature

Open zoonman opened this issue 7 years ago • 7 comments
trafficstars

Allow to define timeout and custom action for it.

zoonman avatar Nov 08 '18 00:11 zoonman

Hey @zoonman - thanks for suggesting this!

Would you mind going into a little more detail about your particular usecase?

AlecAivazis avatar Nov 08 '18 00:11 AlecAivazis

The idea is simple: someone starts the app, it prompts the user to enter configuration parameters. If user accidentally started the app and has not qualified enough to quit (think about some unqualified people) he/she stuck with this strange black window. If we have a timeout, let's say a minute, I can setup hook to gracefully exit. The other thing - app has to be running through a bash script in non-interactive mode (remote server, no access etc). If my app has an interactive setup procedure when is .env file not found it could be hanging forever if deployed through some CD/CI without config.

zoonman avatar Nov 08 '18 01:11 zoonman

Ah interesting. My gut reaction is that this probably belongs in user land and not inside of survey. I'm not quite sure what a "qualified" user is or why they wouldn't be able to just hit ctrl+c to get out of the prompt. However, assuming that we would want to support this in Ask and AskOne, the only way to pull this off without breaking the top level API is to add some global configuration which we've been trying to avoid.

Since you are the first person to bring this up, I'd like to hold off on actually implementing this until more people have voiced a need for it and can give input into the right API.

AlecAivazis avatar Nov 08 '18 16:11 AlecAivazis

Yes. I agree on the hold off. Unqualified user is someone who can't press Ctrl+C. I can give my mom as an example, sadly, she is a technically challenged person.

zoonman avatar Nov 08 '18 18:11 zoonman

fwiw, we have been fighting with prompt timeouts in our testing, so it would be nice to have some strategy to timeout the prompts before the go test global timeout occurs. It seems like we have an opportunity to maybe use a cancellable context (ie context.Context). We could probably introduce this in a non-breaking way via an AskOpt something like WithContext(ctx context.Context) AskOpt.

The tricky bit comes from working with cancellable channels while working with blocking ReadRune operations. In go-expect we created an io.Writer implementation that tries to check the cancel channel while using ReadRune with timeouts.

I will try to put together a PR when I get a chance.

coryb avatar Nov 08 '18 19:11 coryb

Is this still planned?

AkihiroSuda avatar Jun 22 '21 05:06 AkihiroSuda

I would like to see a timeout feature for cases where the default should be used if the user does not actively choose something else. Think of boot options in grub for example, where most of the time the default is okay, but I still can't make it an unchangeable default.

It would be awesome if there was a visible countdown to inform the user about the "time limit" and stop the countdown once any user interaction is received.

jojomi avatar Sep 16 '22 18:09 jojomi