CountdownTimer
No description available
Install / Use
/learn @remember17/CountdownTimerREADME
CountdownTimer
A lightweight countdown manager: use a unique countdownKey to create and manage multiple countdowns; supports normal callbacks and scenario-based subscriptions.
Use Cases
- Multiple countdowns in a list (flash sale, coupons, verification codes)
- Different modules need to subscribe to the same countdown
Features
- Manage multiple countdowns at once
- Multiple scenario callbacks for the same countdown
- Callbacks are delivered on the main thread (safe for UI updates)
Integration
Just add CountdownTimer.swift to your project.
Quick Start
- Define your key:
struct OrderCountdown: Countdownable {
let countdownKey: String
}
- Start a countdown:
let key = OrderCountdown(countdownKey: "order_123")
CountdownTimer.start(key: key, count: 10) { count, finished in
print("Remaining: \(count) seconds")
if finished {
print("Finished")
}
}
- Cancel a countdown:
CountdownTimer.cancel(key: key)
Scenario Subscriptions
Use this when multiple modules need updates from the same countdown:
CountdownTimer.subscribe(key: key, for: "list") { count, finished in
print("List remaining: \(count)")
}
CountdownTimer.subscribe(key: key, for: "detail") { count, finished in
print("Detail remaining: \(count)")
}
// Unsubscribe a scenario
CountdownTimer.unsubscribe(scenario: "list")
API Overview
CountdownTimer.start(key:count:callBack:)CountdownTimer.cancel(key:)CountdownTimer.subscribe(key:for:callBack:)CountdownTimer.unsubscribe(scenario:)
Notes
countdownKeymust be unique, otherwise the countdown is restarted/overwritten.- Callbacks are delivered on the main thread; update UI directly.
License
MIT
Related Skills
node-connect
347.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
