All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.kalasim.animation.AnimationUtil.kt Maven / Gradle / Ivy

package org.kalasim.animation

import org.kalasim.Component

fun  Map.cmeAvoidingCopy(): Map {
    while(true) {
        try {
            return toMap()
        } catch(_: ConcurrentModificationException) {
        }
    }
}

fun  List.cmeAvoidingCopy(): List {
    while(true) {
        try {
            return toList()
        } catch(_: ConcurrentModificationException) {
        }
    }
}



fun  Map.asyncCopy(): Map {
    while(true) {
        try {
            return toMap()
        } catch(_: ConcurrentModificationException) {
        }
    }
}
fun  Set.asyncCopy(): Set {
    while(true) {
        try {
            return toSet()
        } catch(_: ConcurrentModificationException) {
        }
    }
}


fun  List.asyncCopy(): List {
    while(true) {
        try {
            return toMutableList()
        } catch(_: ConcurrentModificationException) {
        }
    }
}

fun  cmeGuard(function: ()->List): List {
    while(true) {
        try {
            return function().toMutableList()
        } catch(_: ConcurrentModificationException) {
        } catch(_: NoSuchElementException) {
        }
    }
}


class AsyncAnimationStop(val rate:Double=1.0): Component(){
    private var stop=false

    fun stop(){
        stop = true
    }
    override fun repeatedProcess()= sequence {
        if(stop){
            stopSimulation()
        }

        hold(1/rate)
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy