Created
July 26, 2017 15:22
-
-
Save pTalanov/f8818b3cdb28f3e365fb8e0a69fdd7c2 to your computer and use it in GitHub Desktop.
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
package kotlin.script.dependencies.experimental | |
import kotlinx.coroutines.experimental.Unconfined | |
import kotlinx.coroutines.experimental.channels.ReceiveChannel | |
import kotlinx.coroutines.experimental.channels.produce | |
import kotlin.script.dependencies.Environment | |
import kotlin.script.dependencies.ScriptContents | |
interface PipelineDependenciesResolver : AsyncDependenciesResolver { | |
/** | |
* Starts resolution pipeline and returns output channel that client can read responses from. | |
* | |
* The resolver must take requests from the [input] channel and place matching responses in the output channel. | |
* | |
* Only the most recent request for a particular script (as identified by `script.file`) is guaranteed to get | |
* a matching response to allow for debouncing. | |
* | |
* A single request can yield multiple responses so as to allow the resolver to react to changes in the external environment. | |
* | |
* The client *must* close the given [input] channel when no more requests are to be expected to allow for the disposal of resources. | |
* | |
* The coroutine completes when the [input] channel is closed or when a fatal error occurs. | |
*/ | |
suspend fun startPipeline(input: ReceiveChannel<Request>): ReceiveChannel<Response> | |
data class Request( | |
/** | |
* The contents of the script. `script.file` is *not guaranteed* to be in sync with `script.text`. | |
*/ | |
val script: ScriptContents, | |
val environment: ScriptEnvironment | |
) | |
data class Response( | |
/** | |
* The request that caused this response. | |
*/ | |
val request: Request, | |
/** | |
* Contains ScriptDependencies and diagnostics | |
*/ | |
val result: ResolutionResult | |
) | |
suspend override fun resolveAsync(scriptContents: ScriptContents, environment: Environment): ResolutionResult { | |
val request = Request(scriptContents, environment) | |
val input = produce(Unconfined) { | |
send(request) | |
close() | |
} | |
val output = startPipeline(input) | |
val response = output.receive() | |
assert(response.request == request) | |
return response.result | |
} | |
} |
We have environment in case we need to share additional information specific to an implementation. Is it not enough?
Right.
Is this regarding resolveAsync implementation?
Yes, that's what triggered my comment about startPipeline
.
Multiple calls wouldn't be a problem as long as the protocol is fully respected, termination semantics and all.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We have environment in case we need to share additional information specific to an implementation. Is it not enough?
Is this regarding
resolveAsync
implementation? I think we need a clear way to conform to previous(simpler) versions of API because this is what compiler is going to call (and older versions of plugin as well). Would multiple calls ofstartPipeline
be a problem?When we release a plugin that supports that API it should call
startPipeline
once (and whenever it needs to restart the connection afterwards).I need to try get a toy implementation of the API going to see if that would be a problem.