Last active
June 20, 2023 19:05
-
-
Save sshaaf/bf5c93cfecc768b3a9c1169e63000781 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import java.math.BigInteger; | |
import java.util.concurrent.StructuredTaskScope; | |
public class ScopedValue21 { | |
private static final ScopedValue<BigInteger> multiplier = ScopedValue.newInstance(); | |
public static void main(String[] args) throws Exception { | |
ScopedValue<String> NAME = ScopedValue.newInstance(); | |
ScopedValue.runWhere(NAME, "duke", () -> System.out.println(NAME.get())); | |
BigInteger number = BigInteger.valueOf(10); | |
var multipiled = ScopedValue.callWhere(multiplier, number, () -> ScopedValue21.squared()); | |
System.out.println(multipiled); | |
ScopedValue.runWhere(multiplier, number, () -> { | |
try (var scope = new StructuredTaskScope<BigInteger>()) { | |
scope.fork(() -> squared()); | |
scope.fork(() -> squared()); | |
scope.fork(() -> squared()); | |
} | |
}); | |
} | |
public static BigInteger squared(){ | |
BigInteger a = multiplier.get(); | |
return a.multiply(a); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment