keepawake is a native-only MoonBit module that exposes a small, readable API
for keeping a machine awake while long-running work is in progress.
This first iteration focuses on a minimal public surface that is easy to maintain and easy to extend:
acquirereturns a guard that starts the native keep-awake request.Guard::releaseends the request and is safe to call more than once.with_keepawakewraps scoped work and releases automatically.Scopekeeps the policy choice explicit without exposing backend details.
Add the module to your project, then import justjavac/keepawake.
moon add justjavac/keepawakePackage configuration:
import {
"justjavac/keepawake",
}let guard = @keepawake.acquire(
reason="Rendering a long animation",
scope=@keepawake.Scope::PreventSystemAndDisplaySleep,
)
// ... perform the long-running work ...
guard.release()Use the scoped helper when you want automatic cleanup:
let result = @keepawake.with_keepawake(
() => {
// ... perform the long-running work ...
"done"
},
reason="Syncing a large local cache",
scope=@keepawake.Scope::PreventSystemSleep,
)The Windows backend uses SetThreadExecutionState, which is the standard API
for declaring thread-level execution requirements.
The macOS backend creates IOKit power assertions. The implementation loads the required frameworks dynamically so the package does not need platform-specific linker flags for this minimal version.
The Linux backend uses systemd-inhibit as the smallest maintainable
cross-distribution starting point for this first version.
PreventSystemSleepmaps tosleepPreventDisplaySleepmaps toidlePreventSystemAndDisplaySleepmaps toidle:sleep
In headless or non-systemd environments the module may raise
BackendUnavailable with a descriptive message instead of pretending the
request succeeded.
Run the example module from the repository root:
moon -C examples run basicThe example acquires a guard, keeps the machine awake for roughly five seconds, and then releases it.
MIT