Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add generateCoroutineMethods plugin option for generating unary callback signatures #9

Merged
merged 21 commits into from
Feb 27, 2023

Conversation

buildbreaker
Copy link
Contributor

@buildbreaker buildbreaker commented Feb 27, 2023

Adding the callbackSignature option for call sites without kotlin coroutines. This change basically exposes the wiring from the generated code to the underlying unary request callback method.

Option Type Default Repeatable Details
generateCallbackMethods Boolean false No Generate callback signatures for unary methods.
generateCoroutineMethods Boolean true No Generate suspend signatures for unary methods.

Interface example:

public interface ElizaServiceClientInterface {
    public suspend fun say(request: NoPackage.SayRequest, headers: Headers = emptyMap()):
        ResponseMessage<NoPackage.SayResponse>

    public fun say(
        request: NoPackage.SayRequest,
        headers: Headers = emptyMap(),
        onResult: (ResponseMessage<NoPackage.SayResponse>) -> Unit
    ): Cancelable
}

Implementation:

public class ElizaServiceClient(
    private val client: ProtocolClientInterface
) : ElizaServiceClientInterface {
    public override suspend fun say(request: NoPackage.SayRequest, headers: Headers):
        ResponseMessage<NoPackage.SayResponse> = client.unary(
        request,
        headers,
        MethodSpec(
            ".ElizaService/Say",
            NoPackage.SayRequest::class,
            NoPackage.SayResponse::class
        )
    )

    public override fun say(
        request: NoPackage.SayRequest,
        headers: Headers,
        onResult: (ResponseMessage<NoPackage.SayResponse>) -> Unit
    ): Cancelable = client.unary(
        request,
        headers,
        MethodSpec(
            ".ElizaService/Say",
            NoPackage.SayRequest::class,
            NoPackage.SayResponse::class
        ),
        onResult
    )
}

@buildbreaker buildbreaker changed the title Add callback_signature plugin option Add callbackSignature plugin option Feb 27, 2023
@buildbreaker buildbreaker changed the title Add callbackSignature plugin option Add callbackSignature plugin option for generating callback signatures Feb 27, 2023
@buildbreaker buildbreaker changed the title Add callbackSignature plugin option for generating callback signatures Add callbackSignature plugin option for generating unary callback signatures Feb 27, 2023
@buildbreaker buildbreaker requested a review from jhump February 27, 2023 19:57
Copy link
Contributor

@rebello95 rebello95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Would it make sense to duplicate crosstests for callbacks vs coroutines (we do in connect-swift)?
  2. Should we add an option to turn off the coroutine API generation (like we have for Swift async/await) so that users don't unnecessarily generate unused code?

@buildbreaker buildbreaker merged commit 1e28ec1 into main Feb 27, 2023
@buildbreaker buildbreaker deleted the ac/add-callback-signature-config branch February 27, 2023 23:35
@buildbreaker buildbreaker changed the title Add callbackSignature plugin option for generating unary callback signatures Add generateCoroutineMethods plugin option for generating unary callback signatures Feb 27, 2023
@buildbreaker buildbreaker changed the title Add generateCoroutineMethods plugin option for generating unary callback signatures Add generateCoroutineMethods plugin option for generating unary callback signatures Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants