-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f350ab1
commit a6a37d4
Showing
5 changed files
with
123 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
snap-tree/src/main/java/org/snapscript/tree/AwaitExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.snapscript.tree; | ||
|
||
import org.snapscript.core.Evaluation; | ||
import org.snapscript.core.Promise; | ||
import org.snapscript.core.constraint.Constraint; | ||
import org.snapscript.core.scope.Scope; | ||
import org.snapscript.core.variable.Value; | ||
|
||
public class AwaitExpression extends Evaluation { | ||
|
||
private final Evaluation evaluation; | ||
|
||
public AwaitExpression(Evaluation evaluation) { | ||
this.evaluation = evaluation; | ||
} | ||
|
||
@Override | ||
public void define(Scope scope) throws Exception { | ||
evaluation.define(scope); | ||
} | ||
|
||
@Override | ||
public Constraint compile(Scope scope, Constraint left) throws Exception { | ||
return evaluation.compile(scope, left); | ||
} | ||
|
||
@Override | ||
public Value evaluate(Scope scope, Value left) throws Exception { | ||
Value value = evaluation.evaluate(scope, left); | ||
Object object = value.getValue(); | ||
|
||
if(Promise.class.isInstance(object)) { | ||
Promise promise = (Promise)object; | ||
Object result = promise.get(); | ||
|
||
return Value.getTransient(result); | ||
} | ||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters