Kroppeb
start
class EncryptionStep{ var key: SecretKey? = null val input: ByteWriteChannel get() = _input val output: ByteReadChannel get() = _output private val _input = ByteChannel() private val _output = ByteChannel() @UseExperimental(InternalAPI::class) fun CoroutineScope.start(encrypted: Pair<ByteReadChannel, ByteWriteChannel>) { launch { _input.read{ runBlocking{ when(val key = key){ null -> encrypted.second.writeAvailable(it) else -> encrypted.second.writeAvailable(encryptData(key, it.moveToByteArray())) } } } } } } fun CoroutineScope.encryptionStep(encrypted: Pair<ByteReadChannel, ByteWriteChannel>): EncryptionStep { val step = EncryptionStep() with(step){ start(encrypted) } return step }
Dominaezzz
runBlocking
CoroutineScope
A modern programming language that makes developers happier.