UNPKG

@ably/cli

Version:

Ably CLI for Pub/Sub, Chat and Spaces

36 lines (35 loc) 1.25 kB
import { Flags } from "@oclif/core"; import { AblyBaseCommand } from "../../base-command.js"; export default class TestWait extends AblyBaseCommand { static description = "Test command that waits for a specified duration"; static hidden = true; // Hide from help static examples = [ "$ ably test:wait --duration 10", "$ ably test:wait -d 5", ]; static flags = { duration: Flags.integer({ char: 'd', description: 'Duration to wait in seconds', required: true, }), }; async run() { const { flags } = await this.parse(TestWait); this.log(`Waiting for ${flags.duration} seconds. Press Ctrl+C to interrupt...`); // Use a simple promise with timeout await new Promise((resolve) => { const timeout = setTimeout(() => { this.log("Wait completed successfully."); resolve(); }, flags.duration * 1000); // Handle cleanup on interrupt const cleanup = () => { clearTimeout(timeout); resolve(); }; process.once('SIGINT', cleanup); process.once('SIGTERM', cleanup); }); } }