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.util.concurrent.CompletableFuture; | |
import java.util.concurrent.ExecutionException; | |
public class AsynchronousExceptionsHandlingWithExceptionally { | |
public static void main(final String[] args) throws InterruptedException, ExecutionException { | |
for (final boolean failure : new boolean[]{false, true}) { | |
CompletableFuture<Integer> x = CompletableFuture.supplyAsync(() -> { | |
if (failure) { | |
throw new RuntimeException("Oops, something went wrong"); |
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.util.concurrent.CompletableFuture; | |
import java.util.concurrent.ExecutionException; | |
public class AsynchronousExceptions { | |
public static void main(final String[] args) throws InterruptedException { | |
for (final boolean failure : new boolean[]{false, true}) { | |
CompletableFuture<Integer> x = CompletableFuture.supplyAsync(() -> { | |
if (failure) { | |
throw new RuntimeException("Oops, something went wrong"); |
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.util.concurrent.CompletableFuture; | |
import java.util.concurrent.ExecutionException; | |
import java.util.concurrent.TimeUnit; | |
import static java.util.concurrent.TimeUnit.SECONDS; | |
public class SynchronousVsAsynchronous { | |
public static void main(final String[] args) { | |
stopwatch(() -> { | |
// Synchronous: | |
int x1 = compute(1); |
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 scala.util.Random | |
def winningCombinationsFor(max: Int = 49, numDrawn: Int = 6, minNumToWin: Int = 3): Seq[Set[Int]] = { | |
val (draw, remainder) = Random.shuffle(1 to max).splitAt(numDrawn) | |
for { | |
numPickedFromDraw <- minNumToWin to numDrawn | |
subsetFromDraw <- draw.toSet.subsets(numPickedFromDraw) | |
subsetFromRemainder <- remainder.toSet.subsets(numDrawn - numPickedFromDraw) | |
} yield subsetFromDraw ++ subsetFromRemainder | |
} |
NewerOlder