1 /** 2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 * SPDX-License-Identifier: Apache-2.0. 4 */ 5 6 package software.amazon.awssdk.crt; 7 8 import java.util.concurrent.CompletableFuture; 9 10 /** 11 * Async io completion abstraction used by the native mqtt layer. We moved to using futures directly but 12 * that might have been a mistake and we should consider moving back to this for our other async 13 * operations that cross the managed/native boundary 14 */ 15 public interface AsyncCallback { 16 wrapFuture(CompletableFuture<T> future, T value)17 static <T> AsyncCallback wrapFuture(CompletableFuture<T> future, T value) { 18 return new AsyncCallback() { 19 @Override 20 public void onSuccess() { 21 future.complete(value); 22 } 23 24 @Override 25 @SuppressWarnings("unchecked") 26 public void onSuccess(Object val) { 27 future.complete((T)(val)); 28 } 29 30 @Override 31 public void onFailure(Throwable reason) { 32 future.completeExceptionally(reason); 33 } 34 }; 35 } 36 37 void onSuccess(); 38 void onSuccess(Object value); 39 void onFailure(Throwable reason); 40 } 41