Rearrange daemonization

This commit is contained in:
Tony Garnock-Jones 2023-10-28 20:01:39 +02:00
parent 882b47602d
commit 9c7b71fa51
3 changed files with 9 additions and 7 deletions

View File

@ -96,9 +96,8 @@ public class Actor {
return _alive && !_isCounted;
}
public synchronized Actor daemonize() {
this._releaseCount();
return this;
public void daemonize() {
this.scheduleTurn(_t -> this._releaseCount());
}
private void _releaseCount() {
@ -138,8 +137,9 @@ public class Actor {
return new Ref(this, o);
}
public void scheduleTurn(Consumer<Turn> f) {
public Actor scheduleTurn(Consumer<Turn> f) {
this.execute(new WorkItem(f, null));
return this;
}
void _performTurn(Consumer<Turn> f) {

View File

@ -8,7 +8,7 @@ import org.syndicate_lang.actors.Turn;
public class Main extends Entity {
public static void main(String[] args) throws InterruptedException {
Actor.convenientLogging();
new Actor().daemonize().scheduleTurn(t -> {
new Actor().scheduleTurn(t -> {
final var vh = Actor.forEntity(new ValueHolder<>("There"));
vh.getActor().daemonize();
final var m = Actor.boot(u -> {
@ -29,7 +29,7 @@ public class Main extends Entity {
})));
}
})));
});
}).daemonize();
Actor.awaitAll();
System.out.println("Overall main returning");

View File

@ -13,7 +13,9 @@ import static java.lang.Integer.parseInt;
public class Main extends Entity {
public static void main(String[] args) throws InterruptedException {
Actor.convenientLogging();
new Actor().daemonize().scheduleTurn(t -> new Main(parseInt(args[0]), parseInt(args[1])).boot(t));
new Actor()
.scheduleTurn(t -> new Main(parseInt(args[0]), parseInt(args[1])).boot(t))
.daemonize();
Actor.awaitAll();
}