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

Support classes that are both Worker and RibCoroutineWorker in co… #629

Merged
merged 1 commit into from
Apr 15, 2024

Conversation

psteiger
Copy link
Contributor

@psteiger psteiger commented Dec 3, 2023

…nverters.

Worker.asRibCoroutineWorker and RibCoroutineWorker.asWorker converters now return the instance unchanged if the class already implements the target interface.

This is important for correctness. For example:

class DualWorker : Worker, RibCoroutineWorker {
  fun onStart(lifecycle: WorkerScopeProvider) {
    doX()
  }

  suspend fun onStart(scope: CoroutineScope) {
    doY()
  }
}

Binding this worker.asWorker() should call doX(), not doY(), and binding this worker.asRibCoroutineWorker() should call doY(), not doX().

@FranAguilera
Copy link
Contributor

FranAguilera commented Dec 4, 2023

@@ -315,3 +355,18 @@ private class TestWorker : RibCoroutineWorker {
}
}
}

private class WorkerAndRibCoroutineWorker(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a comment here regarding that this pattern is not recommended?

…nverters.

`Worker.asRibCoroutineWorker` and `RibCoroutineWorker.asWorker` converters now return the instance unchanged if the class already implements the target interface.

This is important for correctness. For example:

```
class DualWorker : Worker, RibCoroutineWorker {
  fun onStart(lifecycle: WorkerScopeProvider) {
    doX()
  }

  suspend fun onStart(scope: CoroutineScope) {
    doY()
  }
}
```

Binding this `worker.asWorker()` should call `doX()`, not `doY()`, and binding this `worker.asRibCoroutineWorker()` should call `doY()`, not `doX()`.
@FranAguilera FranAguilera merged commit ff46554 into uber:main Apr 15, 2024
2 checks passed
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

Successfully merging this pull request may close these issues.

3 participants