-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deprecate arrow.continuation (#2672)
Co-authored-by: i-walker <[email protected]>
- Loading branch information
Showing
26 changed files
with
166 additions
and
13 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
arrow-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/Effect.kt
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
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
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
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
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
1 change: 1 addition & 0 deletions
1
...ore/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/ShortCircuit.kt
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
package arrow.continuations.generic | ||
|
||
@Deprecated(deprecateArrowContinuation) | ||
public class ShortCircuit internal constructor(internal val token: Token, public val raiseValue: Any?) : ControlThrowable() |
1 change: 1 addition & 0 deletions
1
...-libs/core/arrow-continuations/src/commonMain/kotlin/arrow/continuations/generic/Token.kt
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package arrow.continuations.generic | ||
|
||
/** Represents a unique identifier using object equality. */ | ||
@Deprecated(deprecateArrowContinuation) | ||
internal class Token { | ||
override fun toString(): String = "Token(${hashCode().toString(16)})" | ||
} |
1 change: 1 addition & 0 deletions
1
...-libs/core/arrow-continuations/src/jsMain/kotlin/arrow/continuations/generic/AtomicRef.kt
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
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
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
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
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
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
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
52 changes: 52 additions & 0 deletions
52
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/AtomicRef.kt
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,52 @@ | ||
package arrow.core.continuations | ||
|
||
public expect class AtomicRef<V>(initialValue: V) { | ||
public fun get(): V | ||
public fun set(value: V) | ||
public fun getAndSet(value: V): V | ||
|
||
/** | ||
* Compare current value with expected and set to new if they're the same. Note, 'compare' is checking | ||
* the actual object id, not 'equals'. | ||
*/ | ||
public fun compareAndSet(expected: V, new: V): Boolean | ||
} | ||
|
||
/** | ||
* Infinite loop that reads this atomic variable and performs the specified [action] on its value. | ||
*/ | ||
public inline fun <V> AtomicRef<V>.loop(action: (V) -> Unit): Nothing { | ||
while (true) { | ||
action(get()) | ||
} | ||
} | ||
|
||
public inline fun <V> AtomicRef<V>.update(function: (V) -> V) { | ||
while (true) { | ||
val cur = get() | ||
val upd = function(cur) | ||
if (compareAndSet(cur, upd)) return | ||
} | ||
} | ||
|
||
/** | ||
* Updates variable atomically using the specified [function] of its value and returns its old value. | ||
*/ | ||
public inline fun <V> AtomicRef<V>.getAndUpdate(function: (V) -> V): V { | ||
while (true) { | ||
val cur = get() | ||
val upd = function(cur) | ||
if (compareAndSet(cur, upd)) return cur | ||
} | ||
} | ||
|
||
/** | ||
* Updates variable atomically using the specified [function] of its value and returns its new value. | ||
*/ | ||
public inline fun <V> AtomicRef<V>.updateAndGet(function: (V) -> V): V { | ||
while (true) { | ||
val cur = get() | ||
val upd = function(cur) | ||
if (compareAndSet(cur, upd)) return upd | ||
} | ||
} |
2 changes: 0 additions & 2 deletions
2
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/ior.kt
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
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
30 changes: 30 additions & 0 deletions
30
arrow-libs/core/arrow-core/src/jsMain/kotlin/arrow/core/continuations/AtomicRef.kt
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,30 @@ | ||
package arrow.core.continuations | ||
|
||
public actual class AtomicRef<V> actual constructor(initialValue: V) { | ||
private var internalValue: V = initialValue | ||
|
||
/** | ||
* Compare current value with expected and set to new if they're the same. Note, 'compare' is checking | ||
* the actual object id, not 'equals'. | ||
*/ | ||
public actual fun compareAndSet(expected: V, new: V): Boolean { | ||
return if (expected === internalValue) { | ||
internalValue = new | ||
true | ||
} else { | ||
false | ||
} | ||
} | ||
|
||
public actual fun getAndSet(value: V): V { | ||
val oldValue = internalValue | ||
internalValue = value | ||
return oldValue | ||
} | ||
|
||
public actual fun get(): V = internalValue | ||
|
||
public actual fun set(value: V) { | ||
internalValue = value | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
arrow-libs/core/arrow-core/src/jvmMain/kotlin/arrow/core/continuations/AtomicRef.kt
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,7 @@ | ||
@file:JvmName("AtomicReferenceActual") | ||
|
||
package arrow.core.continuations | ||
|
||
import java.util.concurrent.atomic.AtomicReference | ||
|
||
public actual typealias AtomicRef<V> = AtomicReference<V> |
30 changes: 30 additions & 0 deletions
30
arrow-libs/core/arrow-core/src/nativeMain/kotlin/arrow/core/continuations/AtomicRef.kt
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,30 @@ | ||
package arrow.core.continuations | ||
|
||
import kotlin.native.concurrent.AtomicReference | ||
import kotlin.native.concurrent.freeze | ||
import kotlin.native.concurrent.isFrozen | ||
|
||
public actual class AtomicRef<V> actual constructor(initialValue: V) { | ||
private val atom = AtomicReference(initialValue.freeze()) | ||
public actual fun get(): V = atom.value | ||
|
||
public actual fun set(value: V) { | ||
atom.value = value.freeze() | ||
} | ||
|
||
public actual fun getAndSet(value: V): V { | ||
if (atom.isFrozen) value.freeze() | ||
while (true) { | ||
val cur = atom.value | ||
if (cur === value) return cur | ||
if (atom.compareAndSwap(cur, value) === cur) return cur | ||
} | ||
} | ||
|
||
/** | ||
* Compare current value with expected and set to new if they're the same. Note, 'compare' is checking | ||
* the actual object id, not 'equals'. | ||
*/ | ||
public actual fun compareAndSet(expected: V, new: V): Boolean = | ||
atom.compareAndSet(expected, new.freeze()) | ||
} |
2 changes: 1 addition & 1 deletion
2
...ibs/fx/arrow-fx-coroutines-test/src/jvmMain/kotlin/arrow/fx/coroutines/predef-test-jvm.kt
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
2 changes: 1 addition & 1 deletion
2
arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Atomic.kt
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
2 changes: 1 addition & 1 deletion
2
...w-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/CircuitBreaker.kt
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
4 changes: 2 additions & 2 deletions
4
arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Resource.kt
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
6 changes: 3 additions & 3 deletions
6
arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TVar.kt
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
2 changes: 1 addition & 1 deletion
2
arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/internal/Impl.kt
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