This example demonstrates how to use the rust-ticker library in a web browser.
A 5-second countdown timer:
A simple stopwatch:
// Import the Timer and Stopwatch classes
import { Timer, Stopwatch } from 'rust-ticker';
// Create a timer for 5 seconds
const timer = new Timer(0, 0, 5);
// Start the timer
timer.start().then(() => {
console.log('Timer completed!');
});
// Create a stopwatch
const stopwatch = new Stopwatch();
// Start the stopwatch
stopwatch.start();
// Stop the stopwatch after some time
setTimeout(() => {
const elapsed = stopwatch.stop();
console.log(`Elapsed time: ${elapsed} seconds`);
// Reset the stopwatch
stopwatch.reset();
}, 3000);