I have the following code but I feel like I'm doin...
# coroutines
k
I have the following code but I feel like I'm doing something wrong, mostly in the
start
function
Copy code
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
}
d
Why
runBlocking
?
If you accept a
CoroutineScope
you should return some Job object.
k
?