
org.snapscript.tree.resume.AsyncExecution Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap Show documentation
Show all versions of snap Show documentation
Dynamic scripting for the JVM
The newest version!
package org.snapscript.tree.resume;
import java.util.Iterator;
import org.snapscript.core.Execution;
import org.snapscript.core.result.Result;
import org.snapscript.core.resume.Answer;
import org.snapscript.core.resume.Promise;
import org.snapscript.core.resume.PromiseWrapper;
import org.snapscript.core.resume.Task;
import org.snapscript.core.resume.TaskScheduler;
import org.snapscript.core.resume.Yield;
import org.snapscript.core.scope.Scope;
public class AsyncExecution extends Execution {
private final TaskScheduler scheduler;
private final PromiseWrapper wrapper;
private final Execution execution;
public AsyncExecution(TaskScheduler scheduler, Execution execution) {
this.wrapper = new PromiseWrapper();
this.scheduler = scheduler;
this.execution = execution;
}
@Override
public Result execute(Scope scope) throws Exception {
Result result = execution.execute(scope);
if(!result.isAwait()) {
Object value = result.getValue();
Promise promise = wrapper.toPromise(scope, value);
return Result.getNormal(promise);
}
return execute(scope, result);
}
private Result execute(Scope scope, Result result) throws Exception {
Yield yield = result.getValue();
Iterator
© 2015 - 2025 Weber Informatics LLC | Privacy Policy