From 91356aa7a2bd5087214699469f614e40e1d099d2 Mon Sep 17 00:00:00 2001 From: SaberCon <894876785@qq.com> Date: Mon, 21 Feb 2022 11:59:48 +0800 Subject: [PATCH 1/3] Fix bug in the transaction example --- .../fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/STM.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/STM.kt b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/STM.kt index aa5ca900e0c..ccb6fe4cc4d 100644 --- a/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/STM.kt +++ b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/STM.kt @@ -112,7 +112,7 @@ import arrow.fx.stm.internal.lookupHamtWithHash * * fun STM.withdraw(acc: TVar, amount: Int): Unit { * val current = acc.read() - * if (current - amount >= 0) acc.write(current + amount) + * if (current - amount >= 0) acc.write(current - amount) * else retry() // we now retry if there is not enough money in the account * // this can also be achieved by using `check(current - amount >= 0); acc.write(it + amount)` * } From ad654c653f7affc2a1c34afdce7869235a83ea36 Mon Sep 17 00:00:00 2001 From: SaberCon <894876785@qq.com> Date: Mon, 21 Feb 2022 17:22:47 +0800 Subject: [PATCH 2/3] Fix bug in the transaction example --- .../fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/STM.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/STM.kt b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/STM.kt index ccb6fe4cc4d..895be245622 100644 --- a/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/STM.kt +++ b/arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/STM.kt @@ -55,7 +55,7 @@ import arrow.fx.stm.internal.lookupHamtWithHash * * fun STM.withdraw(acc: TVar, amount: Int): Unit { * val current = acc.read() - * if (current - amount >= 0) acc.write(current + amount) + * if (current - amount >= 0) acc.write(current - amount) * else throw IllegalStateException("Not enough money in the account!") * } * //sampleEnd From 8ab788f0b72792aa2120533ad4a13ab295dc2ebe Mon Sep 17 00:00:00 2001 From: Wenkai Yuan Date: Sun, 27 Feb 2022 22:59:47 +0800 Subject: [PATCH 3/3] Run knit to update the generated documentation --- .../arrow-fx-stm/src/jvmTest/kotlin/examples/example-stm-01.kt | 2 +- .../arrow-fx-stm/src/jvmTest/kotlin/examples/example-stm-02.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arrow-libs/fx/arrow-fx-stm/src/jvmTest/kotlin/examples/example-stm-01.kt b/arrow-libs/fx/arrow-fx-stm/src/jvmTest/kotlin/examples/example-stm-01.kt index c74156a49ce..c48332f9f87 100644 --- a/arrow-libs/fx/arrow-fx-stm/src/jvmTest/kotlin/examples/example-stm-01.kt +++ b/arrow-libs/fx/arrow-fx-stm/src/jvmTest/kotlin/examples/example-stm-01.kt @@ -18,7 +18,7 @@ fun STM.deposit(acc: TVar, amount: Int): Unit { fun STM.withdraw(acc: TVar, amount: Int): Unit { val current = acc.read() - if (current - amount >= 0) acc.write(current + amount) + if (current - amount >= 0) acc.write(current - amount) else throw IllegalStateException("Not enough money in the account!") } diff --git a/arrow-libs/fx/arrow-fx-stm/src/jvmTest/kotlin/examples/example-stm-02.kt b/arrow-libs/fx/arrow-fx-stm/src/jvmTest/kotlin/examples/example-stm-02.kt index bdeaf829b0b..af8152800bb 100644 --- a/arrow-libs/fx/arrow-fx-stm/src/jvmTest/kotlin/examples/example-stm-02.kt +++ b/arrow-libs/fx/arrow-fx-stm/src/jvmTest/kotlin/examples/example-stm-02.kt @@ -21,7 +21,7 @@ fun STM.deposit(acc: TVar, amount: Int): Unit { fun STM.withdraw(acc: TVar, amount: Int): Unit { val current = acc.read() - if (current - amount >= 0) acc.write(current + amount) + if (current - amount >= 0) acc.write(current - amount) else retry() // we now retry if there is not enough money in the account // this can also be achieved by using `check(current - amount >= 0); acc.write(it + amount)` }