Benoît Quenaudon
1 min readFeb 28, 2019

--

Would you be able to develop a bit on how to design APIs for context requiring instance members?

We wanna hook two channels for bidirectional communication over IO, let the consumer to send/receive events. The API could look something like: fun routeChat(context: CoroutineContext): Pair<SendChannel<RequestObject>, ReceiveChannel<ResponseObject>>

We’re not really happy with requiring the context as an argument. Another approach we’re taking is, pulling the coroutineContext intrinsic property instead of requiring an argument, by making the method suspend:suspend fun routeChat(): Pair<SendChannel<RequestObject>, ReceiveChannel<ResponseObject>>

Now, it doesn’t really feel right either because the method is synchronous.

What design pattern would you suggest in this case? I repeat that this is a instance’s member method.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Responses (1)

Write a response