Skip to content

Use nanoTime instead of currentTimeMillis for elapsed time #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/durable_queue.clj
Original file line number Diff line number Diff line change
Expand Up @@ -561,10 +561,10 @@
(while (.get ref)
(when-let [q (.get ref)]
(try
(let [start (System/currentTimeMillis)]
(let [start (System/nanoTime)]
(fsync q)
(let [end (System/currentTimeMillis)]
(Thread/sleep (max 0 (- fsync-interval (- end start))))))
(let [end (System/nanoTime)]
(Thread/sleep (max 0 (- (* 1000000 fsync-interval) (- end start))))))
(catch Throwable e
)))))))

Expand Down Expand Up @@ -758,16 +758,16 @@
"Returns a lazy sequence of tasks that can be consumed in `interval` milliseconds. This will
terminate after that time has elapsed, even if there are still tasks immediately available."
[qs q-name interval]
(let [now (System/currentTimeMillis)]
(let [now (System/nanoTime)]
(lazy-seq
(let [now' (System/currentTimeMillis)
remaining (- interval (- now' now))]
(let [now' (System/nanoTime)
remaining (- (* 1000000 interval) (- now' now))]
(when (pos? remaining)
(let [task (take! qs q-name remaining ::none)]
(when-not (= ::none task)
(cons
task
(interval-task-seq qs q-name (- interval (- (System/currentTimeMillis) now)))))))))))
(interval-task-seq qs q-name (- (* 1000000 interval) (- (System/nanoTime) now)))))))))))

(defn complete!
"Marks a task as complete."
Expand Down