Skip to content
This repository was archived by the owner on Oct 30, 2019. It is now read-only.
This repository was archived by the owner on Oct 30, 2019. It is now read-only.

Add API for explicitly starting/stopping runtimes and spawning futures on a specific runtime #42

Closed
@sdroege

Description

@sdroege

Currently runtimes in runtime are fully implicit and run in the background without any control over their lifetime, what futures get run on them or what (and how many threads) they use.

It would be useful to have API for all of the above. There are a couple of use-cases I can think of, some of which I'm doing with tokio currently in one way or another.

  1. Usage of runtimes in library crates without interfering with any other futures code other library crates or the application might use. This would potentially also go with specific per-thread configuration inside the library crate, for e.g. setting thread priorities of the runtime in a way that is meaningful for what this specific library is doing. See also Ability to have custom initialization for each worker thread #8
  2. Similar to the above, but an extension: plugins. For plugins you might want to use a runtime internally, but at some point you might want to be able to unload the plugin again. Doing so requires to be able to shut down the runtime at a specific point and to ensure that none of the code of the plugin is running anymore.
  3. Error isolation. While this is probably done even better with separate processes, being able to compartmentalize the application into different parts that don't implicitly share any memory with each other could be useful, also for debuggability.
  4. Integration with other runtimes, like the GLib one (see also Integration with GUI event loop #21 (comment)). There you can (and generally do in bigger applications) create and run multiple runtimes (GMainContext / GMainLoop). There's the global default one, which is used also for the GTK+ toolkit to do all the UI things, but if you have other parts of your application doing async operations it often makes sense to create a separate one that runs on another thread (they're always single-threaded) to not interfere with the UI event loop in any way.

I realize that this goes a bit against the goal of making everything as simple as possible to use, but maybe such an API for starting/stopping/configuring runtimes could be made available in addition to the simple, do-it-all-implicitly API.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions