Engine Lifecycle
Start, stop, and manage the Risuko engine in Node.js.
startEngine
Initialize and start the download engine. Must be called before any other API function.
function startEngine(config?: EngineConfig): Promise<void>;EngineConfig
interface EngineConfig {
/** Custom config directory. Default: OS config dir / dev.risuko.app */
configDir?: string;
/** RPC listen port. Default: 16800 */
rpcPort?: number;
/** Whether to start the RPC server. Default: true */
enableRpc?: boolean;
}Examples
import { startEngine } from "@risuko/risuko-js";
// Use defaults
await startEngine();
// Custom configuration
await startEngine({
configDir: "/path/to/config",
rpcPort: 6800,
enableRpc: true,
});Only one engine instance can run per process. Calling startEngine when the engine is already running rejects with an Engine already running error.
What Happens on Start
- The config directory is created (if it doesn't exist)
system.jsonanduser.jsonconfig files are loaded (or defaults created)- The download directory is created
- The task manager is initialized
- Session is restored (torrents resume automatically; other previously active downloads are restored as paused)
- The RPC server is started (if
enableRpcis true) - Background tasks begin: progress updates every second, session auto-save every 30 seconds
stopEngine
Gracefully shut down the engine. Cancels all running downloads, saves the current session, and stops the RPC server and background tasks. Rejects with Engine not running if the engine is not started — as does every other API function.
function stopEngine(): Promise<void>;import { stopEngine } from "@risuko/risuko-js";
await stopEngine();Session Management
saveSession
Persist the current download session to disk. The session is also auto-saved every 30 seconds.
function saveSession(): Promise<void>;purgeDownloadResult
Remove all completed, errored, and removed download results from memory.
function purgeDownloadResult(): Promise<void>;removeDownloadResult
Remove a specific download result by GID. Rejects if the GID is unknown or the download is not stopped. Files on disk are kept.
function removeDownloadResult(gid: string): Promise<void>;Example
import { saveSession, purgeDownloadResult } from "@risuko/risuko-js";
// Force save
await saveSession();
// Clean up finished downloads
await purgeDownloadResult();