epam / epam/CoroutinesCache

Inflight requests

Open
#17 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
165
Forks
7
PR merge metrics
No merged PRs in 30d

Description

Currently the coroutine cache isn't very smart about concurrent requests:

So if we use your readme example but modify it to perform multiple requests concurrently:

```kotlin
class MainActivity : AppCompatActivity() {
private val persistence by lazy { Repository(cacheDir) }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
GlobalScope.launch (Dispatchers.Main) {
repeat(2) {
launch { persistence.getData().await() }
}
}
}
}
```

It performs the network request twice. What would actually be desired here is to have some sort of mutex so the calls will suspend so we don't request the network here twice while a request is already inflight.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.