diff options
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 0000000..ad66416 --- /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 +} |