Skip to content

[Bot Engine] allow asynchronous operations in story handlers #1907

@Fabilin

Description

@Fabilin

Currently, stories in TOCK must answer synchronously, blocking a thread until completion. However, more and more story handler implementations rely on long-running operations, like API calls and LLM routines. As such, it would be useful to have the possibility of writing an asynchronous story handler, which could perform asynchronous operations before sending a message.

Important

TOCK's existing concurrency management relies on Vert.x to manage threads. To keep backward compatibility and avoid creating too many concurrent threads, the new feature should be based on the existing Executor interface.

Possible concurrency APIs

We have a few options to manage concurrency in async stories:

  1. Vert.x tasks: naturally supported, but further exposes Vert.x in our public API. Developers may not be familiar with this API.
  2. CompletableFuture: already supported in Executor. As part of the JDK, developers are likely to be familiar with this API.
  3. Kotlin coroutines: can be bridged from Executor using asCoroutineDispatcher. Kotlin developers are likely to be familiar with this API, and it is the only one that provides structured concurrency.

I believe we should aim to provide support for Kotlin coroutines, as it is the modern standard for Kotlin applications. What are your thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions