Search posts, tags, users, and pages
Yadukrishnan
Software Developer - Scala
Introduction This is the part 7 of the Cats Effect 3 blog series. In this part, we will be looking at the synchronisation primitives available in CE3. Synchronisation and Concurrency When we have mult
Markdown supported · ⌘↵ to post
sammo90
Function "accessWashroom" currentTime code is incomplete. Something like:
def accessWashroom(person: String, sem: Semaphore[IO]): IO[Unit] = for { t0 <- IO(System.currentTimeMillis()) _ <- IO(s"[+ 0 ms] $person wants to access the washroom, waiting for getting the access").trace _ <- sem.acquire t1 <- IO(System.currentTimeMillis()) _ <- IO(s"[+ \({t1 - t0} ms] \)person got access to washroom and using it now").trace _ <- IO.sleep(5.second) t2 <- IO(System.currentTimeMillis()) _ <- IO(s"[+ \({t2 - t0} ms] \)person left the washroom").trace _ <- sem.release } yield ()
does the job.
Wouldn't it be better to use
_ <- IO.println(...
instead of
_ = println( ...
?
Yes, definitely it is better to use it that way to be more functional. I updated it.
sammo90
Function "accessWashroom" currentTime code is incomplete. Something like:
does the job.