Repair Actor.every
This commit is contained in:
parent
7526caa179
commit
6d94e728af
|
@ -151,12 +151,6 @@ public class Actor extends ForkJoinTask<Void> {
|
|||
}
|
||||
}
|
||||
|
||||
private void _performSync(WorkItem item) {
|
||||
synchronized (this) {
|
||||
_perform(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void _perform(WorkItem item) {
|
||||
if (!_alive) {
|
||||
if (item.ifNotAlive != null) item.ifNotAlive.run();
|
||||
|
@ -228,7 +222,7 @@ public class Actor extends ForkJoinTask<Void> {
|
|||
this.execute(item);
|
||||
} else {
|
||||
_scheduledExecutor.schedule(
|
||||
() -> this._performSync(item),
|
||||
() -> this.execute(item),
|
||||
delayMilliseconds,
|
||||
TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
@ -239,7 +233,8 @@ public class Actor extends ForkJoinTask<Void> {
|
|||
final var callback = new Runnable() {
|
||||
PeriodicTimer timer;
|
||||
public void run() {
|
||||
self._performSync(new WorkItem(f, this.timer::cancel));
|
||||
while (this.timer == null) {} // There's a race. Spin.
|
||||
self.execute(new WorkItem(f, this.timer::cancel));
|
||||
}
|
||||
};
|
||||
callback.timer = new PeriodicTimer(
|
||||
|
|
|
@ -11,7 +11,7 @@ public class Main extends Entity {
|
|||
new Actor().scheduleTurn(t -> {
|
||||
final var vh = Actor.forEntity(new ValueHolder<>("There"));
|
||||
vh.getActor().daemonize();
|
||||
final var m = Actor.boot(u -> {
|
||||
Actor.boot(u -> {
|
||||
Main main = new Main();
|
||||
u.later(10, v -> main.run(v, vh));
|
||||
return main;
|
||||
|
@ -38,9 +38,9 @@ public class Main extends Entity {
|
|||
private Actor me;
|
||||
private int greetingCounter = 0;
|
||||
|
||||
public void run(Turn t0, Ref vh) {
|
||||
me = t0.getActor();
|
||||
t0.message_(vh, new IValueHolder.Get(t0.ref(new Entity() {
|
||||
public void run(Turn t, Ref vh) {
|
||||
me = t.getActor();
|
||||
t.message_(vh, new IValueHolder.Get(t.ref(new Entity() {
|
||||
public void message_(Turn t1, Object v1) {
|
||||
Main.this.greet((String) v1);
|
||||
t1.message_(vh, new IValueHolder.Set<>("World"));
|
||||
|
|
|
@ -15,6 +15,7 @@ public class ValueHolder<T> extends Entity {
|
|||
if (body instanceof IValueHolder.Get op) {
|
||||
turn.message_(op.k(), this.value);
|
||||
} else if (body instanceof IValueHolder.Set) {
|
||||
@SuppressWarnings("unchecked")
|
||||
IValueHolder.Set<T> op = (IValueHolder.Set<T>) body;
|
||||
this.value = op.newValue();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue