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

Semantic one-shot channel #985

Closed
tisonkun opened this issue Jun 12, 2023 · 3 comments
Closed

Semantic one-shot channel #985

tisonkun opened this issue Jun 12, 2023 · 3 comments

Comments

@tisonkun
Copy link
Contributor

Different from #199, a semantic one-shot channel may help in reasoning.

That said, bounded(1) doesn't mean the channel will handle only one event all the time, but it can buffer at most one event.

A semantic one-shot channel is like a CountDownLaunch with count=1, which means only one event can be delivered and the following will be rejected with an error.

I don't find an implementation in crossbeam-channel. Thus, I file this issue to see if it's a valid suggestion or we can implement it with current structs.

@taiki-e
Copy link
Member

taiki-e commented Jun 17, 2023

What is the actual purpose of this?

If the purpose is to restrict the API, you might be able to do this just by creating a wrapper type.

If the purpose is performance, it is not clear how large the actual performance benefit is, as I felt the single-capacity optimized variant I tried in #199 was similar to the one used in tokio::sync::oneshot.

@tisonkun
Copy link
Contributor Author

If the purpose is to restrict the API, you might be able to do this just by creating a wrapper type.

That sounds reasonable...Do you have a demo wrapper for such usage?

@tisonkun
Copy link
Contributor Author

I know that I can wrap a OneShotSender that has a fn send(self, ...) now.

Thanks for your well-written library for use!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants