Git Product home page Git Product logo

em-timers's Introduction

em-timers

helper methods for timers in EventMachine

examples:

# Once per hour, starting now. Note the :now symbol must be passed for your block to be called immediately.
EM::Timers.do_hourly(:starting => :now) { puts "drink a beer" }

# Once per day, starting in 1 day.
EM::Timers.do_daily { puts "take a shower" }

# Once per week, starting in 10 hours
EM::Timers.do_weekly(:starting => 10.hours.from_now) { puts "take out the garbage" }

# Once per month, starting at this time tomorrow.
EM::Timers.do_monthly(:starting => 1.day.from_now) { puts "pay the bills" }

# Or you can simply pass a number of seconds til starting
EM::Timers.do_monthly(:starting => 2592000) { puts "pay the bills, in seconds!" }

# Leveraging the Chronic time parsing library. em-timers knows if you have required 
# Chronic and uses it to parse strings if you have. Otherwise, it uses Time.parse.
#
# Every 2 hours, starting next Tuesday at 9AM.
require 'chronic'
EM::Timers.do(:every => 2.hours, :starting => 'next tuesday at 9am') { puts "go pee" }

# You can add up units of time as well
EM::Timers.do(:every => 1.minutes + 3.seconds) { puts "hi!" }

# You can list and cancel timers, too
EM::Timers.list.each { |timer|
  timer.cancel
}


[email protected]
yakischloba on Freenode #eventmachine

em-timers's People

Contributors

jakedouglas avatar

Watchers

 avatar James Cloos avatar  avatar

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.