Munksgaard / session-types

MIT License
555 stars 21 forks source link

Add try_* operations for recv and offer #34

Closed spearman closed 7 years ago

spearman commented 7 years ago

New methods for try_recv and try_offer rely on new internal method try_read_chan that calls mpsc::try_recv and returns an option containing the value if one was pending, and panicking if the channel was closed prematurely.

The offer! macro is adapted to the try_offer! macro which returns the unmodified channel wrapped in Err if no messages were pending. This means the user-defined branches need to return a result, namely the new channel in the chosen branch wrapped in Ok.

Munksgaard commented 7 years ago

This is very cool, @spearman, thanks for contributing!

Before we merge this, do you think it would be possible to write a couple of simple tests, perhaps like the one in test/send_recv.rs?

spearman commented 7 years ago

Added a test for try_recv, there is also an example program in the first commit using try_offer! macro

Munksgaard commented 7 years ago

Thanks!