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

do not panic when failing to create a LocalExecutor #500

Merged
merged 1 commit into from
Jan 17, 2022

Conversation

HippoBaro
Copy link
Member

Errors should propagate to the end users instead. Additionally,
allow returning a struct from the boot future. It is possible to do so
when using the pool builder but not when using the simple one, so this
brings them to parity.

Copy link
Collaborator

@bryandmc bryandmc left a comment

Choose a reason for hiding this comment

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

Besides some stylistic ideas and the API thing regarding what type of result we return, the rest is pretty straight forward and all good.

@@ -592,10 +592,11 @@ impl LocalExecutorBuilder {
/// [`LocalExecutor::run`]:struct.LocalExecutor.html#method.run
#[must_use = "This spawns an executor on a thread, so you may need to call \
`JoinHandle::join()` to keep the main thread alive"]
pub fn spawn<G, F, T>(self, fut_gen: G) -> Result<JoinHandle<()>>
pub fn spawn<G, F, T>(self, fut_gen: G) -> io::Result<JoinHandle<io::Result<T>>>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't these Results be glommio::Error variants to explain to the user what happened? Also shouldn't we just give the user the ability to return a result of their choosing from the main future?

Copy link
Member Author

Choose a reason for hiding this comment

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

We do! The T in there can be anything the user wants. They can return a Result if they so wish. The two errors you see are respectively:

  • The error thrown by join() if the std::thread::Thread failed to create or panicked
  • The error thrown by LocalExecutor::new if we fail to create it

Copy link
Collaborator

Choose a reason for hiding this comment

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

It still seems like we need to return a glommio Error type (not an io::Error, from the io::Result) for functions that are public like this.

glommio/src/channels/shared_channel.rs Outdated Show resolved Hide resolved
@HippoBaro
Copy link
Member Author

I updated the PR to include a new type of JoinHandle that flattens the errors from creating the thread and from creating the local executor inside the thread. This removes all the spurious .unwrap().unwrap() from the last version.

@glommer
Copy link
Collaborator

glommer commented Jan 15, 2022

Agree with Bryan on not using io::Result, but other than that looks good.

Errors should propagate to the end users instead. Additionally,
allow returning a struct from the boot future. It is possible to do so
when using the pool builder but not when using the simple one, so this
brings them to parity.
@HippoBaro
Copy link
Member Author

The latest version uses GlommioError all the way through. Users can now inspect exactly why the executor failed to create 👍

@HippoBaro HippoBaro merged commit 2d7ac8b into DataDog:master Jan 17, 2022
@HippoBaro HippoBaro deleted the propagate_executor_error branch January 17, 2022 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants