GithubHelp home page GithubHelp logo

white_rabbit's Introduction

ci-badge docs-badge rust badge crates.io version

“I'm late! I'm late! For a very important date!”

by “The White Rabbit” 『Alice's Adventures in Wonderland』

About

white_rabbit schedules your tasks and can repeat them!

One funny use case are chat bots, e.g. a remind me-command that might be repeated after a user-specified time.

We are using chrono's DateTime<Utc>, enabling you to serialise and thus backup currently running tasks, in case you want to shutdown/restart your application, constructing a new scheduler is doable. However, please make sure your internal clock is synced.

Everyone is welcome to contribute, check out the CONTRIBUTING.md for further guidance.

Example

Let's have a look at a code-example:

use white_rabbit::{DateResult, Duration, Scheduler};

fn main() {
    let mut scheduler = Scheduler::new(4);

    scheduler.add_task_duration(Duration::seconds(5), |_| {
        println!("I'm here!");

        DateResult::Done
    });
}

Precision

The scheduler sleeps when unneeded. Due to preemption or different implementations across operating systems, it may occur that the scheduler will sleep longer than intended.

Be aware, an incorrect system clock may lead to tasks being run earlier or later.

Installation

Add this to your Cargo.toml:

[dependencies]
white_rabbit = "0.1.0"

white_rabbit's People

Contributors

lakelezz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

white_rabbit's Issues

Make Context time accessible

Tasks are handed a Context reference on execution. I would like to access the context's time to schedule a follow-up task based on it. The field is private though and there is no accessor method. (I know that I could just call now() to get the current time, which should be almost equal to the time stored in the context. But then the task might be delayed slightly each time it is rescheduled).

Delete scheduled Tasks

Deleting scheduled tasks is a feature I would like to add.
It will require to change the underlying data-structure.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.