Skip to content

Set of I/O-free Rust coroutines to manage timers

License

Notifications You must be signed in to change notification settings

rohitparteti/io-timer

Repository files navigation

🕒 io-timer: A Lightweight Timer Library for Rust

GitHub Release License

Welcome to the io-timer repository! This project offers a set of I/O-free Rust coroutines designed to efficiently manage timers. With a focus on simplicity and performance, io-timer allows you to create and manage timers without the overhead of I/O operations.

Table of Contents

  1. Introduction
  2. Features
  3. Installation
  4. Usage
  5. Examples
  6. Contributing
  7. License
  8. Releases
  9. Contact

Introduction

In modern applications, timers play a crucial role in scheduling tasks and managing delays. The io-timer library provides a lightweight and efficient solution for creating timers using Rust coroutines. By avoiding I/O operations, this library ensures high performance and low resource consumption.

Features

  • I/O-free: Operates without any I/O dependencies, making it lightweight.
  • Coroutines: Utilizes Rust's coroutine capabilities for efficient task management.
  • Simple API: Easy-to-use interface for creating and managing timers.
  • Performance: Optimized for speed and low memory usage.
  • Flexible: Supports various timer configurations to suit different use cases.

Installation

To use io-timer in your Rust project, add the following to your Cargo.toml:

[dependencies]
io-timer = "0.1"

Then, run the following command to install the library:

cargo build

Usage

Here’s a quick guide on how to use io-timer in your project. First, import the library:

use io_timer::Timer;

Next, create a new timer:

let timer = Timer::new();

You can start the timer with a specified duration:

timer.start(5); // Starts a timer for 5 seconds

To check if the timer has finished, you can use:

if timer.is_finished() {
    println!("Timer has finished!");
}

For more advanced usage, refer to the Examples section.

Examples

Here are a few examples to demonstrate how to use the io-timer library effectively.

Basic Timer Example

use io_timer::Timer;

fn main() {
    let timer = Timer::new();
    timer.start(10); // Start a 10-second timer

    while !timer.is_finished() {
        // Do some work
    }

    println!("Timer finished!");
}

Multiple Timers

You can create multiple timers and manage them independently:

use io_timer::Timer;

fn main() {
    let timer1 = Timer::new();
    let timer2 = Timer::new();

    timer1.start(5); // 5 seconds
    timer2.start(10); // 10 seconds

    while !timer1.is_finished() || !timer2.is_finished() {
        if timer1.is_finished() {
            println!("Timer 1 finished!");
        }
        if timer2.is_finished() {
            println!("Timer 2 finished!");
        }
    }
}

Custom Timer Callbacks

You can also define custom actions when the timer finishes:

use io_timer::Timer;

fn main() {
    let timer = Timer::new();
    timer.start(3); // 3 seconds

    while !timer.is_finished() {
        // Wait for the timer to finish
    }

    on_timer_finished();
}

fn on_timer_finished() {
    println!("Custom action: Timer finished!");
}

Contributing

We welcome contributions to io-timer! If you would like to contribute, please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and commit them.
  4. Push your changes to your fork.
  5. Submit a pull request.

Please ensure that your code follows the project's coding standards and includes appropriate tests.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Releases

You can find the latest releases of io-timer here. Please download and execute the appropriate file for your system.

Contact

For any questions or feedback, feel free to reach out to the maintainer:

Thank you for your interest in io-timer! We hope this library helps you manage timers efficiently in your Rust applications. For more updates, please check the Releases section regularly.