Skip to content

Commit c4e6d6a

Browse files
authored
[core] rename Sync.Unsafe.apply to Sync.Unsafe.defer (#1466)
I changed `Sync.apply` to `Sync.defer` some time ago but forgot to rename `Sync.Unsafe.apply` as well.
1 parent 39f055d commit c4e6d6a

File tree

37 files changed

+252
-246
lines changed

37 files changed

+252
-246
lines changed

kyo-cats/shared/src/main/scala/kyo/Cats.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ object Cats:
1616
* A Kyo effect that, when run, will execute the cats.effect.IO
1717
*/
1818
def get[A](io: => CatsIO[A])(using Frame): A < (Abort[Nothing] & Async) =
19-
Sync.Unsafe {
19+
Sync.Unsafe.defer {
2020
import cats.effect.unsafe.implicits.global
2121
val p = Promise.Unsafe.init[A, Any]()
2222
val (future, cancel) = io.unsafeToFutureCancelable()

kyo-core/jvm-native/src/main/scala/kyo/internal/AsyncPlatformSpecific.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ private[kyo] class AsyncPlatformSpecific:
99
fromCompletionStage(cs)
1010

1111
def fromCompletionStage[A](cs: CompletionStage[A])(using Frame): A < Async =
12-
Sync.Unsafe {
12+
Sync.Unsafe.defer {
1313
val p = Promise.Unsafe.init[A, Any]()
1414
cs.whenComplete { (success, error) =>
1515
if error == null then p.completeDiscard(Result.succeed(success))

kyo-core/shared/src/main/scala/kyo/Adder.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ final case class LongAdder private (unsafe: LongAdder.Unsafe):
3636
* @return
3737
* Unit
3838
*/
39-
inline def add(v: Long)(using inline frame: Frame): Unit < Sync = Sync.Unsafe(unsafe.add(v))
39+
inline def add(v: Long)(using inline frame: Frame): Unit < Sync = Sync.Unsafe.defer(unsafe.add(v))
4040

4141
/** Decrements the sum by one.
4242
*
@@ -45,7 +45,7 @@ final case class LongAdder private (unsafe: LongAdder.Unsafe):
4545
* @return
4646
* Unit
4747
*/
48-
inline def decrement(using inline frame: Frame): Unit < Sync = Sync.Unsafe(unsafe.decrement())
48+
inline def decrement(using inline frame: Frame): Unit < Sync = Sync.Unsafe.defer(unsafe.decrement())
4949

5050
/** Increments the sum by one.
5151
*
@@ -54,7 +54,7 @@ final case class LongAdder private (unsafe: LongAdder.Unsafe):
5454
* @return
5555
* Unit
5656
*/
57-
inline def increment(using inline frame: Frame): Unit < Sync = Sync.Unsafe(unsafe.increment())
57+
inline def increment(using inline frame: Frame): Unit < Sync = Sync.Unsafe.defer(unsafe.increment())
5858

5959
/** Returns the current sum.
6060
*
@@ -64,7 +64,7 @@ final case class LongAdder private (unsafe: LongAdder.Unsafe):
6464
* @return
6565
* The current sum
6666
*/
67-
inline def get(using inline frame: Frame): Long < Sync = Sync.Unsafe(unsafe.get())
67+
inline def get(using inline frame: Frame): Long < Sync = Sync.Unsafe.defer(unsafe.get())
6868

6969
/** Resets the sum to zero.
7070
*
@@ -73,7 +73,7 @@ final case class LongAdder private (unsafe: LongAdder.Unsafe):
7373
* @return
7474
* Unit
7575
*/
76-
inline def reset(using inline frame: Frame): Unit < Sync = Sync.Unsafe(unsafe.reset())
76+
inline def reset(using inline frame: Frame): Unit < Sync = Sync.Unsafe.defer(unsafe.reset())
7777

7878
/** Returns the current sum and resets it to zero.
7979
*
@@ -83,7 +83,7 @@ final case class LongAdder private (unsafe: LongAdder.Unsafe):
8383
* @return
8484
* The sum before reset,
8585
*/
86-
inline def sumThenReset(using inline frame: Frame): Long < Sync = Sync.Unsafe(unsafe.sumThenReset())
86+
inline def sumThenReset(using inline frame: Frame): Long < Sync = Sync.Unsafe.defer(unsafe.sumThenReset())
8787

8888
end LongAdder
8989

@@ -103,7 +103,7 @@ object LongAdder:
103103
* The result of applying the function
104104
*/
105105
inline def initWith[A, S](inline f: LongAdder => A < S)(using inline frame: Frame): A < (Sync & S) =
106-
Sync.Unsafe(f(LongAdder(Unsafe.init())))
106+
Sync.Unsafe.defer(f(LongAdder(Unsafe.init())))
107107

108108
/** WARNING: Low-level API meant for integrations, libraries, and performance-sensitive code. See AllowUnsafe for more details. */
109109
opaque type Unsafe = j.LongAdder
@@ -158,7 +158,7 @@ final case class DoubleAdder private (unsafe: DoubleAdder.Unsafe):
158158
* @return
159159
* Unit
160160
*/
161-
inline def add(v: Double)(using inline frame: Frame): Unit < Sync = Sync.Unsafe(unsafe.add(v))
161+
inline def add(v: Double)(using inline frame: Frame): Unit < Sync = Sync.Unsafe.defer(unsafe.add(v))
162162

163163
/** Returns the current sum.
164164
*
@@ -168,7 +168,7 @@ final case class DoubleAdder private (unsafe: DoubleAdder.Unsafe):
168168
* @return
169169
* The current sum
170170
*/
171-
inline def get(using inline frame: Frame): Double < Sync = Sync.Unsafe(unsafe.get())
171+
inline def get(using inline frame: Frame): Double < Sync = Sync.Unsafe.defer(unsafe.get())
172172

173173
/** Resets the sum to zero.
174174
*
@@ -177,7 +177,7 @@ final case class DoubleAdder private (unsafe: DoubleAdder.Unsafe):
177177
* @return
178178
* Unit
179179
*/
180-
inline def reset(using inline frame: Frame): Unit < Sync = Sync.Unsafe(unsafe.reset())
180+
inline def reset(using inline frame: Frame): Unit < Sync = Sync.Unsafe.defer(unsafe.reset())
181181

182182
/** Returns the current sum and resets it to zero.
183183
*
@@ -187,7 +187,7 @@ final case class DoubleAdder private (unsafe: DoubleAdder.Unsafe):
187187
* @return
188188
* The sum before reset,
189189
*/
190-
inline def sumThenReset(using inline frame: Frame): Double < Sync = Sync.Unsafe(unsafe.sumThenReset())
190+
inline def sumThenReset(using inline frame: Frame): Double < Sync = Sync.Unsafe.defer(unsafe.sumThenReset())
191191

192192
end DoubleAdder
193193

@@ -207,7 +207,7 @@ object DoubleAdder:
207207
* The result of applying the function
208208
*/
209209
inline def initWith[A, S](inline f: DoubleAdder => A < S)(using inline frame: Frame): A < (Sync & S) =
210-
Sync.Unsafe(f(DoubleAdder(Unsafe.init())))
210+
Sync.Unsafe.defer(f(DoubleAdder(Unsafe.init())))
211211

212212
/** WARNING: Low-level API meant for integrations, libraries, and performance-sensitive code. See AllowUnsafe for more details. */
213213
opaque type Unsafe = j.DoubleAdder

kyo-core/shared/src/main/scala/kyo/AllowUnsafe.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Options (in order of preference):
1111
def myFunction(implicit allow: AllowUnsafe) = // unsafe code here
1212
1313
2. Suspend the operation with Sync
14-
Sync.Unsafe { // unsafe code here }
14+
Sync.Unsafe.defer { // unsafe code here }
1515
1616
3. Import implicit evidence (last resort)
1717
import AllowUnsafe.embrace.danger

kyo-core/shared/src/main/scala/kyo/Async.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ object Async extends AsyncPlatformSpecific:
168168
isolate.capture { state =>
169169
Fiber.initUnscoped(isolate.isolate(state, v)).map { task =>
170170
Clock.use { clock =>
171-
Sync.Unsafe {
171+
Sync.Unsafe.defer {
172172
val sleepFiber = clock.unsafe.sleep(after)
173173
sleepFiber.onComplete(_ => discard(task.unsafe.interrupt(Result.Failure(Timeout(Present(after))))))
174174
task.unsafe.onComplete(_ => discard(sleepFiber.interrupt()))
@@ -743,7 +743,7 @@ object Async extends AsyncPlatformSpecific:
743743
* A nested computation that returns the memoized result
744744
*/
745745
def memoize[A, S](v: A < S)(using Frame): A < (S & Async) < Sync =
746-
Sync.Unsafe {
746+
Sync.Unsafe.defer {
747747
val ref = AtomicRef.Unsafe.init(Maybe.empty[Promise.Unsafe[A, Any]])
748748
@tailrec def loop(): A < (S & Async) =
749749
ref.get() match
@@ -752,14 +752,14 @@ object Async extends AsyncPlatformSpecific:
752752
val promise = Promise.Unsafe.init[A, Any]()
753753
if ref.compareAndSet(Absent, Present(promise)) then
754754
Abort.run(v).map { r =>
755-
Sync.Unsafe {
755+
Sync.Unsafe.defer {
756756
if !r.isSuccess then
757757
ref.set(Absent)
758758
promise.completeDiscard(r.map(Kyo.lift))
759759
Abort.get(r)
760760
}
761761
}.handle(Sync.ensure {
762-
Sync.Unsafe {
762+
Sync.Unsafe.defer {
763763
if !promise.done() then
764764
ref.set(Absent)
765765
}

0 commit comments

Comments
 (0)