Last active
April 8, 2017 20:41
-
-
Save Groostav/970bdd65993b6acb8f1198fe1337e671 to your computer and use it in GitHub Desktop.
Sample current pipe code on our codebase
This file contains hidden or 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
import some.jna | |
import some.dtos | |
import some.other.domainmodels | |
makeEncodingAndConnectingPipe(/* makes a connected pipes using Win32 CreateNamedPipe over JNA */).use { pipe -> | |
pipe.writeMessage(json(StartMessage)) | |
expect<StartAck>(pipe.readMessage()) | |
while(isBusinessLogic()){ | |
pipe.writeMessage(json(NextIteration(mapOf("x1" to 1.0, "x2" to 2.0)))) | |
val result = expect<IterationResults>(pipe.readMessage()) | |
val resultActual = result ?: continue | |
doBusinessLogic(resultActual) | |
} | |
pipe.writeMessage(json(DoneMessage)) | |
expect<DoneAck>(pipe.readMessage()) | |
} | |
private fun <reified T> expect(val responseText): T? where T: MessageDTO { | |
//reads a value from the pipe, deserializes it, logs an error if its decodable as a T | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment