Skip to content

Instantly share code, notes, and snippets.

@vasmarfas
Created May 19, 2022 08:42
Show Gist options
  • Select an option

  • Save vasmarfas/1c19d5e9f91bbf73108e74c9fe86b3d0 to your computer and use it in GitHub Desktop.

Select an option

Save vasmarfas/1c19d5e9f91bbf73108e74c9fe86b3d0 to your computer and use it in GitHub Desktop.
import kotlinx.coroutines.*
import java.util.Objects
class SortingCentre(
val loadingPortsAmount: Int = 1,
val unloadingPortsAmount: Int = 3
) {
class FirstLoadingPort: LoadingPort() {
}
class SecondLoadingPort: LoadingPort() {
}
fun unloading() {
}
}
suspend fun startWork() = runBlocking {
launch {
val trucksForUnload = mutableListOf<Truck>()
for (i in 0 until settings.totalUnloadTrucks) {
trucksForUnload.add(TruckGenerator.randomTruck())
}
}
}
open class LoadingPort() {
open fun loading(loadingProduct: Objects) {
}
}
open class UnloadingPort() {
open fun unloading() {
}
}
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.produce
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlin.random.Random
object TruckGenerator {
val channel = Channel<Truck>()
/* fun CoroutineScope.produceNumbers() = produce<Int> {
var x = 1 // start from 1
while (true) {
send(x++) // produce next
delay(100) // wait 0.1s
}
} */
fun generator() = runBlocking {
launch {
channel.send(randomTruck())
}
}
fun randomTruck(): Truck {
var returnTruck: Truck
returnTruck = when (Random.nextInt(0,2)) {
0 -> TruckBig()
1 -> TruckMedium()
2 -> TruckSmall()
else -> Truck(0)
}
return returnTruck
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment