rust-ticker Web Example

This example demonstrates how to use the rust-ticker library in a web browser.

Timer Example

A 5-second countdown timer:

00:00:05

Stopwatch Example

A simple stopwatch:

00:00:00

Code Example


// 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);