Last active
November 28, 2023 20:52
-
-
Save Kikimora/9dcfb8afb72ed0e87435705e08f9232c to your computer and use it in GitHub Desktop.
SyncAsync.java
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
//Given below definitions implement MySyncApiImpl.operation and MySyncApiImpl.cancelOperation methods. | |
//Send me a link to github repo or a gist with your implementation. | |
public interface Callback { | |
void onSuccess(int result); | |
} | |
public interface ErrorCallback { | |
void onError(MyApiException error); | |
} | |
public interface Cancellable { | |
void cancel(); | |
} | |
public class MyApiException extends Exception {} | |
public interface MyAsyncApi { | |
Cancellable operation(int param, Callback onSuccess, ErrorCallback onError); | |
} | |
public class MySyncApiImpl { | |
public MySyncApiImpl(MyAsyncApi api) { | |
this.api = api; | |
} | |
/** | |
* Runs MyAsyncApi.operation and blocks until it finishes. Throws IllegalStateException if called while operation is running. | |
*/ | |
public int operation(int param) throws MyApiException { | |
//Please implement this method using this.api | |
} | |
/** | |
* Cancel most recent operation started with 'operation' method. | |
* Return true of operation was cancelled and false otherwise. | |
*/ | |
public boolean cancelOperation() { | |
//Cancel the running operation. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment