This commit is contained in:
2026-01-25 10:50:20 +01:00
parent e4a94d576b
commit 735596fdf6
48 changed files with 1543 additions and 86 deletions
+50
View File
@@ -0,0 +1,50 @@
// retoor <retoor@molodetz.nl>
import "scheduler" for Scheduler, Future
class Counter {
construct new(start) {
_value = start
}
value { _value }
add(n) {
var op = async { |x|
_value = _value + x
return _value
}
return await op(n)
}
subtract(n) {
var op = async { |x|
_value = _value - x
return _value
}
return await op(n)
}
reset() {
var op = async {
_value = 0
return _value
}
return await op()
}
}
var counter = Counter.new(10)
System.print(counter.value) // expect: 10
System.print(counter.add(5)) // expect: 15
System.print(counter.value) // expect: 15
System.print(counter.subtract(3)) // expect: 12
System.print(counter.value) // expect: 12
System.print(counter.reset()) // expect: 0
System.print(counter.value) // expect: 0
System.print(counter.add(10)) // expect: 10
System.print(counter.subtract(3)) // expect: 7