ZIO Clock MILLISECONDS and System.currentTimeMillis

 Scala Worksheet

import java.util.concurrent.TimeUnit
import zio.clock.Clock
import zio.console.putStrLn
import zio.console.Console
import zio.duration.durationInt
import zio.{ExitCode, Runtime, ZEnv, ZIO}

val prg: ZIO[Console with Clock, Throwable, Int] = for {

 c <- ZIO.access[Clock](_.get)
 zio_begin <- c.currentTime(TimeUnit.MILLISECONDS)
 zio_beginM <- ZIO.accessM[Clock](_.get.currentTime(TimeUnit.MILLISECONDS))
 sys_begin <- ZIO.succeed(System.currentTimeMillis)
 _ <- putStrLn(s" zio_begin  = $zio_begin")
 _ <- putStrLn(s" zio_beginM = $zio_beginM")
 _ <- putStrLn(s" sys_begin  = $sys_begin")

 _ <- c.sleep(1.second)

 zio_end <- c.currentTime(TimeUnit.MILLISECONDS)
 zio_endM <- ZIO.accessM[Clock](_.get.currentTime(TimeUnit.MILLISECONDS))
 sys_end <- ZIO.succeed(System.currentTimeMillis)
 _ <- putStrLn(s"  zio_end  = $zio_end")
 _ <- putStrLn(s"  zio_endM = $zio_beginM")
 _ <- putStrLn(s"  sys_end  = $sys_end")

 _ <- putStrLn(s" duration zio  = ${zio_end - zio_begin} ms.")
 _ <- putStrLn(s" duration zioM = ${zio_endM - zio_beginM} ms.")
 _ <- putStrLn(s" duration sys  = ${sys_end - sys_begin} ms.")
} yield 1

object MyApp extends App{
   def run(args: List[String]): ZIO[ZEnv,Nothing,ExitCode] =
    prg.provideLayer(ZEnv.live).exitCode
}

val runtime = Runtime.default
runtime.unsafeRun(MyApp.run(List[String]()))
<- -="" 1="" _="" app="" args:="" c.currenttime="" c.sleep="" code="" def="" duration="" exitcode="" extends="" get="" imeunit.milliseconds="" ist="" list="" lock="" ms.="" myapp="" nv.live="" nv="" object="" othing="" prg.providelayer="" putstrln="" run="" runtime.unsaferun="" runtime="Runtime.default" s="" second="" sys="${sys_end" sys_begin="" sys_end="$sys_end" tring="" val="" xitcode="" yapp.run="" yield="" ystem.currenttimemillis="" zio.access="" zio.succeed="" zio="" zio_begin="" zio_end="$zio_end">

Output 


runtime: zio.Runtime[zio.ZEnv] = zio.Runtime$$anon$3@5b952a40
 zio_begin  = 1605551185584
 zio_beginM = 1605551185585
 sys_begin  = 1605551185599
  zio_end  = 1605551186631
  zio_endM = 1605551185585
  sys_end  = 1605551186638
 duration zio  = 1047 ms.
 duration zioM = 1050 ms.
 duration sys  = 1039 ms.
res0: zio.ExitCode = ExitCode(0)

Комментарии

Популярные сообщения из этого блога

Loading data into Spark from Oracle RDBMS, CSV

Load data from Cassandra to HDFS parquet files and select with Hive

Hadoop 3.0 cluster - installation, configuration, tests on Cent OS 7