Skip to content

Builder pattern and extended functionality #9

Description

@Enyium

First, a better name for SingletonProcess could be SingletonProcessGuard or even just singleton_process::Guard (comparable API from std).

A builder type SingletonProcessGuardBuilder/singleton_process::GuardBuilder that build()s a singleton_process::Guard would allow to extend the functionality. Setters on the builder type:

  • fn name(self, name: &str) -> Self
  • fn exit_code(self, code: u8) -> Self (u8 as in ExitCode's From implementation; default: 0, or ExitCode::SUCCESS if that type would be usable [only in Nightly])
  • fn exit_msg(self, msg: &str) -> Self (printed with println!() before process::exit())
  • fn terminate(self, process: Option<RedundantProcess>) -> Self accepts an enum RedundantProcess with the variants Current and Other/Original (default: None). None (no termination at all) would be useful if the app developer wants to return from their main() function instead of accepting the implications of process::exit() that destructors aren't running, or they want to use something like the interprocess crate to tell the other process - which could be an async app - to shut down gracefully (if this still requires this crate).
    • singleton_process::Guard::new() would then need to fail with a new Error variant OtherProcessExists/AlreadyRunning that the caller can handle how they see fit.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions