-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 馃幐 monotonic and realTime lambdas in Clock class
- Loading branch information
1 parent
cf14590
commit 0f21aba
Showing
1 changed file
with
24 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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package vertx.effect; | ||
|
||
import vertx.effect.exp.Cons; | ||
|
||
import java.time.Duration; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public final class Clock { | ||
|
||
private Clock(){} | ||
|
||
public static 位<Void,Long> monotonic = v -> Cons.success(System.nanoTime()); | ||
|
||
public static 位<Void,Long> realTime = v -> Cons.success(System.currentTimeMillis()); | ||
|
||
public static 位<Void,Long> monotonic(TimeUnit unit){ | ||
return v -> monotonic.apply(null).map( time -> unit.convert(Duration.ofNanos(time))); | ||
} | ||
|
||
public static 位<Void,Long> realTime(TimeUnit unit){ | ||
return v -> realTime.apply(null).map( time -> unit.convert(Duration.ofMillis(time))); | ||
} | ||
|
||
} |