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