Socket
Book a DemoInstallSign in
Socket

easy_timers

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easy_timers

1.1.0
bundlerRubygems
Version published
Maintainers
1
Created
Source

EasyTimers

Build Status

A simple interface for creating timers with callbacks that handles all the threading for you.

Installation

Add this line to your application's Gemfile:

gem 'easy_timers'

Or install it yourself as:

$ gem install easy_timers

Usage

Create a new group of timers with EasyTimers::Timers.new:

require 'easy_timers'

timers = EasyTimers::Timers.new

Schedule a timer to execute 10 seconds from now with EasyTimers::Timers#after:

timers.after(10) { puts "Hello world" }

Now timers has a single timer that will call its block in ten seconds.

You can also supply a ruby Time object instead of an interval.

the_future = Time.now + 10
timers.after(the_future) { put "Ten seconds have passed." }

If you want to be able to cancel a specific timer, you should give it a name:

timers.after(60, :one_minute) { puts "It's been 60 seconds." }
# do some work and decide to change our mind
timers.cancel(:one_minute)

If you'd rather not mint your own names, one will be generated for you:

timer_name = timers.after(10) { puts "hai" }
timers.cancel(timer_name)

You can also create periodic timers with EasyTimers::Timers#every:

timer_name = timers.every(1) { puts "One second has passed." }

Periodic timers will be scheduled repeatedly until cancelled.

Need a combination of the above? You can schedule a period timer to start at a certain time, then scheduled repeatedly using a different interval:

timer_name = timers.after_then_every(0.5, 0.1, :my_timer) { puts "tic toc" }

The above timer will first fire after half a second, then fire every 0.1 seconds thereafter.

Contributing

  • Fork it ( https://github.com/malakai97/easy_timers/fork )
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create a new Pull Request

FAQs

Package last updated on 28 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.