Created
July 29, 2019 10:03
-
-
Save zarinfam/fd0c64f747bfdcf28bbd51baf736dc55 to your computer and use it in GitHub Desktop.
Created with Copy to Gist
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
public synchronized void printText(String text) throws PrintingException { | |
final CompletableFuture<SuccessResult> result = new CompletableFuture(); | |
PrintingListener printingListener = new PrintingListener() { | |
@Override | |
public void onSuccess(SuccessResult successResult) { | |
result.complete(successResult); | |
} | |
@Override | |
public void onFailure(FailureResult failureResult) { | |
result.completeExceptionally(new PrintingException(PrintTask.RESULT_FAILURE)); | |
} | |
@Override | |
public void onTimeout(TimeoutResult timeoutResult) { | |
result.completeExceptionally(new PrintingException(PrintTask.RESULT_TIMEOUT)); | |
} | |
}; | |
printerApi.startPrinting(text, printingListener); | |
try { | |
result.join(); | |
} catch (CompletionException ex) { | |
throw (PrintingException) ex.getCause(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment