Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
emil-bar committed Jan 7, 2025
1 parent a7676f3 commit a5cc213
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.StructuredTaskScope;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
* Capability granted by an {@link Scopes#supervised(Scoped)} or {@link Scopes#unsupervised(ScopedUnsupervised)}
Expand All @@ -15,8 +17,11 @@
* @see ScopedUnsupervised
*/
public class Scope extends UnsupervisedScope {


private final StructuredTaskScope<Object> scope;
private final Supervisor supervisor;
private final Lock externalSchedulerLock = new ReentrantLock();
private ActorRef<ExternalScheduler> externalSchedulerActor;

Scope(Supervisor supervisor) {
Expand Down Expand Up @@ -118,8 +123,13 @@ public <T> Fork<T> forkUser(Callable<T> f) {
* ExternalRunner#runAsync(ThrowingConsumer) for running functions within the scope
*/
public ExternalRunner externalRunner() {
if (externalSchedulerActor == null) {
externalSchedulerActor = ActorRef.create(this, r -> r.accept(Scope.this));
externalSchedulerLock.lock();
try {
if (externalSchedulerActor == null) {
externalSchedulerActor = ActorRef.create(this, r -> r.accept(Scope.this));
}
} finally {
externalSchedulerLock.unlock();
}
return new ExternalRunner(externalSchedulerActor);
}
Expand Down

0 comments on commit a5cc213

Please sign in to comment.