Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

An easy to use Java Timer wrapper for clojure.

tree: e209770f63

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 src
Octocat-spinner-32 .gitignore
Octocat-spinner-32 README.md
Octocat-spinner-32 project.clj
README.md

ruiyun.tools.timer

The ruiyun.tools.timer is a Java Timer and TimerTask wrapper for Clojure.

Installation

Add the following to your project.clj or pom.xml:

Lein artifact:

[ruiyun/tools.timer "1.0.0-SNAPSHOT"]

Maven:

<dependency>
  <groupId>ruiyun</groupId>
  <artifactId>tools.timer</artifactId>
  <version>1.0.0-SNAPSHOT</version>
</dependency>

Then execute

lein deps

Quick tutorial

You can simply start a period task in every 5 seconds immediately like this:

(use 'ruiyun.tools.timer)
(run-task! #(println "Say hello every 5 seconds.") :period 5000)

If you want delay the first run with 2 seconds:

(run-task! #(println "Say hello after 2 seconds.") :dealy 2000)

Use this if you want to execute a task at an absolute time:

(run-task! #(println "Say hello at 2013-01-01T00:00:00 in beijing.") :at #inst "2013-01-01T00:00:00+08:00")

And, you can use the same timer in more than one tasks:

(def greeting-timer (timer "The timer for greeting"))
(run-task! #(println "Say hello after 2 seconds.") :dealy 2000 :by greeting-timer)
(run-task! #(println "Say hello every 5 seconds.") :period 5000 :by greeting-timer)

Finally, you can cancel a timer's tasks:

(cancel! greeting-timer)

Documentation

For more detailed information on ruiyun.tools.timer, please refer to the documentation.

License

Copyright (C) 2012 Ruiyun Wen

Distributed under the Eclipse Public License, the same as Clojure.

Something went wrong with that request. Please try again.