Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Result to TaskState #1366

Open
realmazharhussain opened this issue Apr 9, 2024 · 0 comments
Open

Rename Result to TaskState #1366

realmazharhussain opened this issue Apr 9, 2024 · 0 comments

Comments

@realmazharhussain
Copy link

Loading is a state, not a result. Result means an outcome. Something's outcome is always either Success or Failure. A Failure is caused by an error (a.k.a. Throwable).

A task can be in one of the following states;

  • Not Started (not useful)
  • Ongoing/In Progress
  • Ended (either successfully or unsuccessfully)

A result of a task is also one of its states (Ended). Because of that, Success and Failure can easily be incorporated into TakState.

In the end, what we get is:

sealed interface TaskState<out T> {
    data class Success<T>(val data: T) : TaskState<T>
    data class Failure(val cause: Throwable) : TaskState<Nothing>
    data object Ongoing : TaskState<Nothing>
}

If this is acceptable, let me know, I'll open a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant