AM
Size: a a a
AM
AS
private fun CoroutineScope.asyncWait(timeout: Long, units: TimeUnit) = async {
synchronized(lock) {
try {
lock.wait(units.toMillis(timeout))
} catch (ex: TimeoutException) {
}
}
}
GlobalScope.launch {
while(true) {
if(tryCounts.get() >= 3) {
Logger.info("Waiting 45 seconds")
asyncWait(45, TimeUnit.SECONDS).await()
}
try {
... отправка
tryCounts.set(0)
} catch(ex: Exception) {
ex.printStackTrace()
tryCounts.incrementAndGet()
}
}
}
AM
synchronized
и корутины — несовместимые штуки.VP
private fun CoroutineScope.asyncWait(timeout: Long, units: TimeUnit) = async {
synchronized(lock) {
try {
lock.wait(units.toMillis(timeout))
} catch (ex: TimeoutException) {
}
}
}
GlobalScope.launch {
while(true) {
if(tryCounts.get() >= 3) {
Logger.info("Waiting 45 seconds")
asyncWait(45, TimeUnit.SECONDS).await()
}
try {
... отправка
tryCounts.set(0)
} catch(ex: Exception) {
ex.printStackTrace()
tryCounts.incrementAndGet()
}
}
}
AS
synchronized
и корутины — несовместимые штуки.fun wakeUp() {
synchronized(lock) {
lock.notifyAll()
}
}
AM
select
, но я так и не научился им пока пользоваться.AS
AM
VP
cancel()
.AS
AO
fun main() {
class Foo {
operator fun invoke(f: (Int) -> Int): Int = f(1)
}
fun foo() = Foo()
foo() { it + 1 }
}
AO
AO
foo()() { it + 1}
foo().invoke { it + 1}
AS
AS
AO
val foo = Foo()
foo { it + 1}
AO
AS
AO
AS