-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: do not write wrappers for writer/reader
- Loading branch information
Showing
14 changed files
with
73 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package technology.idlab.extensions | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.channels.Channel | ||
import kotlinx.coroutines.channels.SendChannel | ||
import kotlinx.coroutines.launch | ||
|
||
internal fun <E, R> Channel<E>.map(scope: CoroutineScope, func: (R) -> E): SendChannel<R> { | ||
// Create the new channel. | ||
val result = Channel<R>() | ||
|
||
// Pipe the data through the function and into the new channel. | ||
scope.launch { | ||
for (data in result) { | ||
this@map.send(func(data)) | ||
} | ||
} | ||
|
||
// Close the new channel if required. | ||
this.invokeOnClose { result.close() } | ||
|
||
// Return the new channel. | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
package technology.idlab.std | ||
|
||
import java.io.File | ||
import kotlinx.coroutines.channels.SendChannel | ||
import technology.idlab.runner.impl.jvm.Arguments | ||
import technology.idlab.runner.impl.jvm.Processor | ||
import technology.idlab.runner.impl.jvm.Writer | ||
|
||
class FileReader(args: Arguments) : Processor(args) { | ||
/** Arguments */ | ||
private val path: String = arguments["path"] | ||
private val output: Writer = arguments["output"] | ||
private val output: SendChannel<ByteArray> = arguments["output"] | ||
|
||
/** Read the file as a single byte array and push it down the pipeline. */ | ||
override suspend fun exec() { | ||
val file = File(path) | ||
val bytes = file.readBytes() | ||
output.push(bytes) | ||
output.send(bytes) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,22 @@ | ||
package technology.idlab.std | ||
|
||
import kotlinx.coroutines.channels.ReceiveChannel | ||
import kotlinx.coroutines.channels.SendChannel | ||
import technology.idlab.runner.impl.jvm.Arguments | ||
import technology.idlab.runner.impl.jvm.Processor | ||
import technology.idlab.runner.impl.jvm.Reader | ||
import technology.idlab.runner.impl.jvm.Writer | ||
import technology.idlab.util.Log | ||
|
||
class Transparent(args: Arguments) : Processor(args) { | ||
private val input: Reader = arguments["input"] | ||
private val output: Writer = arguments["output"] | ||
private val input: ReceiveChannel<ByteArray> = arguments["input"] | ||
private val output: SendChannel<ByteArray> = arguments["output"] | ||
|
||
override suspend fun exec() { | ||
output.push(input.read()) | ||
Log.shared.debug { "Transparent processor started" } | ||
for (data in input) { | ||
Log.shared.debug { "Received ${data.size} bytes" } | ||
output.send(data) | ||
} | ||
output.close() | ||
Log.shared.debug { "Transparent processor finished" } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.