william
10/23/2020, 12:11 PMclass PersistentWsClient() {
private val scope = CoroutineScope(Dispatchers.Default)
private val sendingQueue = Channel<Frame>(UNLIMITED)
fun open(host: String, path: String, port: Int = 8080) {
scope.launch {
this@PersistentWsClient.e("waiting for messages")
for (msg in sendingQueue) {
this@PersistentWsClient.e(msg.toString())
}
}
}
fun send(payload: Frame) {
scope.launch {
for (i in 0..10) {
delay(500)
sendingQueue.offer(payload)
this.e("offering $payload")
}
}
sendingQueue.offer(payload)
}
}
(i have stripped away some extra code).
In this example i only ever get
waiting for messages
offering <payload>
offering <payload>
...
william
10/23/2020, 12:15 PMtravis
10/23/2020, 1:27 PMinvokeOnCompletion
listener to the receiving launch
or a log message after the iteration to make sure it's still receiving from the chanel?travis
10/23/2020, 1:30 PMoffer
calls are returning true
.william
10/23/2020, 4:20 PMoffer
is returning true
. hmmmwilliam
10/23/2020, 4:25 PMscope.launch
it does seem to work (???)
fun send(payload: Frame) {
scope.launch {
launch {
for (i in 0..10) {
delay(500)
this@PersistentWsClient.e("offering? ${sendingQueue.offer(payload)} for $payload")
}
}
launch {
for (frame in sendingQueue) {
this@PersistentWsClient.e(frame.toString())
}
}
}
}
travis
10/23/2020, 4:43 PMclass MainActivity : AppCompatActivity() {
private lateinit var ws: PersistentWsClient
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
ws = PersistentWsClient()
ws.open("localhost", "/")
setContentView(R.layout.activity_main)
val button: Button = findViewById(R.id.test)
button.setOnClickListener {
(0..10).forEach { ws.send(Frame(it)) }
}
}
}
data class Frame(val value: Int)
class PersistentWsClient {
private val scope = CoroutineScope(Dispatchers.Default)
private val sendingQueue = Channel<Frame>(UNLIMITED)
fun open(host: String, path: String, port: Int = 8080) {
scope.launch {
e("waiting for messages")
for (msg in sendingQueue) {
e(msg.toString())
}
}
}
fun send(payload: Frame) {
scope.launch {
for (i in 0..10) {
delay(500)
sendingQueue.offer(payload)
e("offering $payload")
}
}
// sendingQueue.offer(payload)
}
private fun e(msg: String) { println(msg) }
}
2020-10-23 09:42:24.965 12926-13073/com.example.myapplication I/System.out: offering Frame(value=1)
2020-10-23 09:42:24.965 12926-13073/com.example.myapplication I/System.out: Frame(value=1)
2020-10-23 09:42:24.966 12926-13073/com.example.myapplication I/System.out: offering Frame(value=8)
2020-10-23 09:42:24.966 12926-13073/com.example.myapplication I/System.out: Frame(value=8)
2020-10-23 09:42:24.967 12926-13073/com.example.myapplication I/System.out: offering Frame(value=9)
2020-10-23 09:42:24.967 12926-13073/com.example.myapplication I/System.out: Frame(value=9)
2020-10-23 09:42:24.967 12926-13073/com.example.myapplication I/System.out: offering Frame(value=10)
2020-10-23 09:42:24.968 12926-13073/com.example.myapplication I/System.out: Frame(value=10)
2020-10-23 09:42:24.970 12926-13072/com.example.myapplication I/System.out: offering Frame(value=0)
2020-10-23 09:42:24.970 12926-13072/com.example.myapplication I/System.out: Frame(value=0)
2020-10-23 09:42:24.970 12926-13068/com.example.myapplication I/System.out: offering Frame(value=4)
2020-10-23 09:42:24.970 12926-12960/com.example.myapplication I/System.out: offering Frame(value=6)
...
william
10/23/2020, 6:07 PMtravis
10/23/2020, 6:09 PMtravis
10/23/2020, 6:10 PMwilliam
10/23/2020, 6:18 PMval commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
implementation(Versions.Libs.COROUTINES_CORE)
...
const val COROUTINES_CORE = "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9"
in my android module i have
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9")
i'll have to try and reduce it to an isolated example and publish that / make a bug report if it is still an issuetravis
10/23/2020, 6:27 PMi'll have to try and reduce it to an isolated example and publish that / make a bug report if it is still an issueYa, I think this would be the best option for getting further help and/or reporting a potential bug.
william
10/24/2020, 4:09 PMtravis
10/24/2020, 4:20 PM