Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f7c6705
Showing
5 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,12 @@ | |||
/pom.xml | |||
*jar | |||
/lib | |||
/classes | |||
/native | |||
/.lein-failures | |||
/checkouts | |||
/.lein-deps-sum | |||
/.idea/ | |||
*.iml | |||
/autodoc | |||
autodoc/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,49 @@ | |||
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 | |||
|
|||
And here is an example to show how to work with ruiyun.tools.timer. | |||
|
|||
```clojure | |||
(use 'ruiyun.tools.timer) | |||
TBD.. | |||
``` | |||
|
|||
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. | |||
|
|||
[Timer]: http://docs.oracle.com/javase/7/docs/api/java/util/Timer.html | |||
[TimerTask]: http://docs.oracle.com/javase/7/docs/api/java/util/TimerTask.html | |||
[Clojure]: http://clojure.org/ | |||
[documentation]: http://ruiyun.github.com/tools.timer/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
(defproject ruiyun/tools.timer "1.0.0-SNAPSHOT" | |||
:description "An easy to use Java Timer wrapper for clojure." | |||
:dependencies [[org.clojure/clojure "1.4.0"]] | |||
:dev-dependencies [[lein-autodoc "0.9.0"]] | |||
:autodoc {:name "ruiyun.tools.timer", :page-title "ruiyun.tools.timer API Documentation"}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,72 @@ | |||
(ns ^{:doc "place doc string here" | |||
:author "ruiyun"} | |||
ruiyun.tools.timer.core | |||
(:use cljain.tools.predicate) | |||
(:import [java.util Timer TimerTask Date])) | |||
|
|||
(defn timer | |||
"Create a new java.util.Timer object." | |||
{:added "0.2.0"} | |||
([] (Timer.)) | |||
([name] (Timer. name))) | |||
|
|||
(defn deamon-timer | |||
"Create a new java.util.Timer object with deamon option." | |||
{:added "0.2.0"} | |||
[] | |||
(Timer. true)) | |||
|
|||
(defmacro task | |||
"Create a java.util.TimerTask object with some code." | |||
{:arglists '([body*]) | |||
:added "0.2.0"} | |||
[& body] | |||
`(proxy [TimerTask] [] | |||
(run [] | |||
~@body))) | |||
|
|||
(defmulti run! | |||
"Execute a timer task, then return the timer user passed or created auto. | |||
User must set one of the two options: | |||
:at <time> | |||
:delay <milliseconds> | |||
Optional, user can set | |||
:period <milliseconds>" | |||
{:arglists '([timer? task & options]) | |||
:added "0.2.0"} | |||
(fn [a & more] (class a))) | |||
|
|||
(defn- run-task! | |||
"The 'run!' functions internal implement." | |||
{:added "0.2.0"} | |||
[timer task & {:keys [at delay period]}] | |||
{:pre [(or (instance? Date at) (>= delay 0)) | |||
(or (nil? period) (> period 0))] | |||
:post [(instance? Timer %)]} | |||
(let [start-time at] | |||
(cond | |||
(not (nil? start-time)) | |||
(if (nil? period) | |||
(.schedule timer task start-time) | |||
(.schedule timer task start-time period)) | |||
|
|||
(not (nil? delay)) | |||
(if (nil? period) | |||
(.schedule timer task delay) | |||
(.schedule timer task delay period))) | |||
timer)) | |||
|
|||
(defmethod run! Timer | |||
[timer task & options] | |||
(apply run-task! timer task options)) | |||
|
|||
(defmethod run! TimerTask | |||
[task & options] | |||
(apply run-task! (timer) task options)) | |||
|
|||
(defn cancel! | |||
"Terminates a timer, discarding any currently scheduled tasks." | |||
{:added "0.2.0"} | |||
[timer] | |||
(.cancel timer)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,6 @@ | |||
(ns ruiyun.tools.timer.test.core | |||
(:use [ruiyun.tools.timer.core]) | |||
(:use [clojure.test])) | |||
|
|||
(deftest replace-me ;; FIXME: write | |||
(is false "No tests have been written.")) |