Skip to content

Instantly share code, notes, and snippets.

@Groostav
Last active April 8, 2017 20:41
Show Gist options
  • Save Groostav/970bdd65993b6acb8f1198fe1337e671 to your computer and use it in GitHub Desktop.
Save Groostav/970bdd65993b6acb8f1198fe1337e671 to your computer and use it in GitHub Desktop.
Sample current pipe code on our codebase
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