Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Conversation

@bkchr
Copy link
Member

@bkchr bkchr commented Apr 30, 2020

Up to now BasicQueue expected a closure that to spawn a Future.
This was expected to be a closure that spawns a blocking future.
However, this wasn't documented anywhere. This pr introduces a new trait
SpawnBlocking that exposes this requirement to the outside.

polkadot-companion: paritytech/polkadot#1061

Up to now `BasicQueue` expected a closure that to spawn a `Future`.
This was expected to be a closure that spawns a blocking future.
However, this wasn't documented anywhere. This pr introduces a new trait
`SpawnBlocking` that exposes this requirement to the outside.
@bkchr bkchr added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes labels Apr 30, 2020
);

spawner(future.boxed());
spawner.spawn_blocking("basic-block-import-worker", future.boxed());
Copy link
Contributor

Choose a reason for hiding this comment

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

@tomaka might need to update his grafana dashboard :)

}

/// Something that can spawn a blocking future.
pub trait SpawnBlocking: futures::task::Spawn {
Copy link
Contributor

@tomaka tomaka May 1, 2020

Choose a reason for hiding this comment

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

Suggested change
pub trait SpawnBlocking: futures::task::Spawn {
pub trait SpawnBlocking {

Let's not make it optional to pass a name.

@tomaka
Copy link
Contributor

tomaka commented May 1, 2020

When I see a new trait being introduced, I can't help but be annoyed. This adds a lot of complexity and contributes to the spaghetti-ification for not much.

Basically all of our Futures are "blocking" because we call in the client. The import queue is just a worst case scenario in that it is probably does more database accesses than the others, but there's no fundamental distinction between a "blocking" and a "non-blocking" future. The TaskType enum is just a hint.

If this really needs to be done, what about changing the closure to accept an additional TaskType parameter instead? That would be consistent with the API of sc_service.

@Demi-Marie
Copy link
Contributor

I agree with @tomaka on this.

@bkchr
Copy link
Member Author

bkchr commented May 1, 2020

The point why I come up with this, because I needed to port the changes to Cumulus. If I would just have read the documentation, I would probably just have spawned the future without using spawn_blocking. However I looked into the code and copy pasted the code, but this can not be the way we write code. The interface should express this and not require some opaque closure that takes a future.

I don't understand how forwarding random closures can help to solve anything? Especially as this random closure directly sets an opioniated name for the future. What happens when I refactor the BasicQueue and need to spawn another future? Right, I would use the closure and spawn another future using the same name. This increases the spaghettification of the code.

I would like to have used a upstream trait as well, but there is nothing.

Copy link
Contributor

@gnunicorn gnunicorn left a comment

Choose a reason for hiding this comment

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

lgtm

@bkchr bkchr merged commit 3039413 into master May 4, 2020
@bkchr bkchr deleted the bkchr-spawn-blocking branch May 4, 2020 17:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants