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

[bug] SubmitCallback and GetCallBack functions must be coroutines. #142

Closed
jiyoonie9 opened this issue Jan 26, 2024 · 1 comment · Fixed by #147
Closed

[bug] SubmitCallback and GetCallBack functions must be coroutines. #142

jiyoonie9 opened this issue Jan 26, 2024 · 1 comment · Fixed by #147

Comments

@jiyoonie9
Copy link
Contributor

this bug was found during an attempt at writing an example http-server in kotlin using TbdexHttpServer.

fun main() {
  val serverConfig = TbdexHttpServerConfig(
    port = 8080,
    pfiDid = DidDht.create(InMemoryKeyManager()).uri,
    offeringsApi = FakeOfferingsApi(),
    exchangesApi = FakeExchangesApi()
  )

  val tbdexServer = TbdexHttpServer(serverConfig)


  tbdexServer.submit(SubmitKind.rfq) { call, messageKind, offering ->
    println("Saving RFQ...")
    println("Validating RFQ.claims against Offering...")
    println("Generating a Quote...")
    println("Saving a Quote...")

    // this line does not compile
    // error message: Suspend function 'respond' should be called only from a coroutine or another suspend function
    call.respond(HttpStatusCode.Accepted)
  }

  tbdexServer.start()

}

in order to return a response, the callback must call ApplicationCall.respond() which is a coroutine function. therefore, the callback must also be a coroutine.

changing typealias SubmitCallback = (ApplicationCall, MessageKind, Offering?) -> Unit to typealias SubmitCallback = suspend (ApplicationCall, MessageKind, Offering?) -> Unit seems to do the trick, but needs testing to confirm.

@jiyoonie9 jiyoonie9 changed the title [bug] SubmitCallback and GetCallBack functions must be coroutines [bug] SubmitCallback and GetCallBack functions must be coroutines. Also, callbacks must pass in the Message, not MessageKind Jan 31, 2024
@jiyoonie9 jiyoonie9 changed the title [bug] SubmitCallback and GetCallBack functions must be coroutines. Also, callbacks must pass in the Message, not MessageKind [bug] SubmitCallback and GetCallBack functions must be coroutines. Jan 31, 2024
@chris-tbd
Copy link
Contributor

@jiyoontbd closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants