Skip to content

Commit

Permalink
Update task.md
Browse files Browse the repository at this point in the history
language checked
  • Loading branch information
stephen-hero authored and kochaika committed Dec 12, 2023
1 parent a310b4a commit c590777
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions Coroutines/Suspending functions/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,22 @@ interface GitHubService {
Alternatively, Retrofit allows returning the result wrapped in `Response`. In this case, the result body is
provided, and it is possible to check for errors manually. This tutorial uses the versions that return `Response`.

See the new declarations `getOrgRepos` and `getRepoContributors` in [src/contributors/GitHubService.kt](course://Coroutines/Suspending functions/src/contributors/GitHubService.kt)
See the new declarations for `getOrgRepos` and `getRepoContributors` in [src/contributors/GitHubService.kt](course://Coroutines/Suspending functions/src/contributors/GitHubService.kt)

## Task

Your task is to change the code of the function that loads contributors to make use of two new suspending functions,
`getOrgRepos()` and `getRepoContributors()`. The new `loadContributorsSuspend()` function is marked as `suspend` to use the
Your task is to change the function code that loads contributors to make use of two new suspending functions,
`getOrgRepos()` and `getRepoContributors()`. The new `loadContributorsSuspend()` function is marked as `suspend` in order to use the
new API.

> Suspending functions can't be called everywhere. Calling a suspending function from `loadContributorsBlocking()` will
> result in an error with the message "Suspend function 'getOrgRepos' should be called only from a coroutine or another
> suspend function".

1. Copy the implementation of `loadContributorsBlocking()` that is defined in [src/tasks/Request1Blocking.kt](course://Coroutines/Suspending functions/src/tasks/Request1Blocking.kt)
into the `loadContributorsSuspend()` that is defined in [src/tasks/Request4Suspend.kt](course://Coroutines/Suspending functions/src/tasks/Request4Suspend.kt).
2. Modify the code so that the new suspending functions are used instead of the ones that return `Call`s.
3. Run the program by choosing the _SUSPEND_ option and ensure that the UI is still responsive while the GitHub requests
are performed.
1. Copy the implementation of `loadContributorsBlocking()` defined in [src/tasks/Request1Blocking.kt](course://Coroutines/Suspending functions/src/tasks/Request1Blocking.kt)
into `loadContributorsSuspend()` defined in [src/tasks/Request4Suspend.kt](course://Coroutines/Suspending functions/src/tasks/Request4Suspend.kt).
2. Modify the code so that the new suspending functions replace the ones that return `Call`s.
3. Run the program by choosing the _SUSPEND_ option and ensure that the UI remains responsive during the execution of GitHub requests.

For a more detailed description, you can look at [this article](https://kotlinlang.org/docs/coroutines-and-channels.html#suspending-functions)
For a more detailed description, you can refer to [this article](https://kotlinlang.org/docs/coroutines-and-channels.html#suspending-functions).

0 comments on commit c590777

Please sign in to comment.