Hello Im new to Kotlin and Androidstudio, I want to use this:
actor
Solved:
Because the syntax of using actors seems to be very nice ( val c = actor{…})
But Androidstudio cant resolve actor and if I try to add “import kotlinx.coroutines.channels” I get “Unresolved reference: coroutines”. How do I use coroutines? Is it because coroutines are Obsolete? I thought In the future I would simply need to replace actor with complex actors.
Edit: Changing title from “How to import kotlinx.coroutines.channels in Androidstuduio?” to “Pls help me creating my first Actor”
Update2:
ok seems like Im solving slowly. Now I have this:
val myFirstActor = GlobalScope.actor<String> {
var sometestvar = 0for (msg in channel) {
//some code
}}
Maybe this solves everything I must look if I run into problems with this.
Update:
Nah Im at the point there I dont know what Im doing. I have this
@ObsoleteCoroutinesApi
fun ActorScope.myFirstActor() = actor {
var sometestvar = 0for (msg in channel) {
//some code
}}
but neither myFirstActor.send()
nore val someActor = myFirstActor
works (because myFirstActor() is a funcion?). I cant realy read lamdas and the code above I wrote is a lamda if Im correct. I just want to use actors, abstracting away from threads and coroutines and memory and so on but I either find old examples or background information but no hello world example for a simple actor (without the need to create a new class. I want them as simple as java methods() just immagine you would need to create a new class everytime you create a new method() ).