Pls help me creating my first Actor

#1

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 = 0

for (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 = 0

for (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() ).

#2

Kotlinx-coroutines is a separate library, so you should add it to the project to be able to use it. MavenCentral repository artifact is here.

#3

I followed this it seems to work:

The Gradle and Android part are relevant for Android Studio.

the creation of my first simple actor was painful because there was no example. I used ActorScope to do it there is no example in the internet for that. But I haven’t tested if it’s doing what I’m expecting yet. But the example with val c = actor{…} seems to be outdated.