This file contains 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
val user = getUserInfo() | |
val friendList = getFriendList(user) | |
val feedList = getFeedList(friendList) |
This file contains 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
getUserInfo(new CallBack() { | |
@Override | |
public void onSuccess(String response) { | |
if (response != null) { | |
System.out.println(response); | |
} | |
} | |
}); |
This file contains 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
getUserInfo(new CallBack() { | |
@Override | |
public void onSuccess(String user) { | |
if (user != null) { | |
System.out.println(user); | |
getFriendList(user, new CallBack() { | |
@Override | |
public void onSuccess(String friendList) { | |
if (friendList != null) { | |
System.out.println(friendList); |
This file contains 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
// delay(1000L) representing request to server | |
//Suspending Function | |
// ↓ | |
suspend fun getUserInfo(): String { | |
withContext(Dispatchers.IO) { | |
delay(1000L) | |
} | |
return "BoyCoder" | |
} |
This file contains 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
suspend fun getUserInfo(): String { | |
withContext(Dispatchers.IO) { | |
delay(1000L) | |
} | |
return "BoyCoder" | |
} |
This file contains 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
// Continuation is nothing but CallBack | |
// ↓ | |
public static final Object getUserInfo(Continuation $completion) { | |
... | |
return "BoyCoder"; | |
} |
This file contains 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 interface Continuation<in T> { | |
public val context: CoroutineContext | |
// just like: onSuccess(result) | |
// ↓ ↓ | |
public fun resumeWith(result: Result<T>) | |
} |
This file contains 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
interface CallBack { | |
void onSuccess(String response); | |
} |
This file contains 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
suspend fun getUserInfo(): String { | |
withContext(Dispatchers.IO) { | |
delay(1000L) | |
} | |
return "BoyCoder" | |
} |
This file contains 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
// suspend modifier | |
// ↓ | |
suspend fun noSuspendFriendList(user: String): String{ | |
// body is just like normal function | |
return "Tom, Jack" | |
} |
OlderNewer