diff options
author | Koni Marti <koni.marti@gmail.com> | 2022-07-11 20:23:41 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-07-14 23:15:02 +0200 |
commit | e200cd56bf22ec48d1b0441be2355dc6dcb35cd4 (patch) | |
tree | bc7b5bce028281fdf11bcfbdb5db221f8fa4d27a /commands/mode/noquit.go | |
parent | 5102d32ceabf4292a4af7d528f7ba5f070183518 (diff) | |
download | aerc-e200cd56bf22ec48d1b0441be2355dc6dcb35cd4.tar.gz |
commands: implement a no-quit mode
Add a mode that prevents aerc from quitting normally when an important
task is performed, i.e. when sending a message. The no-quit mode will be
ignored when quit is used with the -f option to force an exit.
Suggested-by: ph14nix[m]
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands/mode/noquit.go')
-rw-r--r-- | commands/mode/noquit.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/commands/mode/noquit.go b/commands/mode/noquit.go new file mode 100644 index 00000000..ad664165 --- /dev/null +++ b/commands/mode/noquit.go @@ -0,0 +1,26 @@ +package mode + +import "sync/atomic" + +// noquit is a counter for goroutines that requested the no-quit mode +var noquit int32 + +// NoQuit enters no-quit mode where aerc cannot be exited (unless the force +// option is used) +func NoQuit() { + atomic.AddInt32(&noquit, 1) +} + +// NoQuitDone leaves the no-quit mode +func NoQuitDone() { + atomic.AddInt32(&noquit, -1) +} + +// QuitAllowed checks if aerc can exit normally (only when all goroutines that +// requested a no-quit mode were done and called the NoQuitDone() function) +func QuitAllowed() bool { + if atomic.LoadInt32(&noquit) > 0 { + return false + } + return true +} |