Commit 25574882 authored by Tom Niget's avatar Tom Niget

Actor mutex example works

parent e33bf6d1
......@@ -40,15 +40,10 @@ struct TyMutex__oo : classtype<_Base0, TyMutex__oo<>> {
auto typon$$sync(auto, auto) -> TyNone const { return None; }
auto operator()(auto _self, auto callback) -> typon::Task<TyNone> const {
print("1"_ps);
auto self = arc(_self);
print("2"_ps);
auto lock = dot(self, mutex).lock();
print("3"_ps);
co_await lock;
print("4"_ps);
co_await callback(ref(dot(self, cell)));
print("5"_ps);
co_return None;
}
} static constexpr when{};
......
......@@ -10,22 +10,18 @@ class Actor[T]:
return future(lambda: self.mutex.when(f))
def inc(cell):
print("inc")
#print("inc")
x = cell.val
sleep(1)
cell.val = x + 1
print("current:", cell.val)
def truc():
print("a")
a = Actor(0)
print("b")
for i in range(10):
print("spawn", i)
a.when(inc)
print("spawned", i)
future = a.when(lambda cell: print("final:", cell.val))
# future.get()
future.get()
print("done")
if __name__ == "__main__":
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment