Skip to content

Commit

Permalink
Add a sleep method that takes scala.concurrent.duration, with docum…
Browse files Browse the repository at this point in the history
…entation (#51)
  • Loading branch information
natsukagami authored Mar 11, 2024
1 parent aad1146 commit 9723588
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions shared/src/main/scala/async/AsyncOperations.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
package gears.async

import scala.concurrent.duration.FiniteDuration

trait AsyncOperations:
/** Suspends the current [[Async]] context for at least [[millis]] milliseconds. */
def sleep(millis: Long)(using Async): Unit

object AsyncOperations:
/** Suspends the current [[Async]] context for at least [[millis]] milliseconds.
* @param millis
* The duration to suspend. Must be a positive integer.
*/
inline def sleep(millis: Long)(using AsyncOperations, Async): Unit =
summon[AsyncOperations].sleep(millis)

/** Suspends the current [[Async]] context for at least [[millis]] milliseconds.
* @param duration
* The duration to suspend. Must be positive.
*/
inline def sleep(duration: FiniteDuration)(using AsyncOperations, Async): Unit =
sleep(duration.toMillis)

0 comments on commit 9723588

Please sign in to comment.