ballerina-platform / ballerina-spec

Ballerina Language and Platform Specifications
Other
168 stars 53 forks source link

Support optional receive action #1284

Open jclark opened 9 months ago

jclark commented 9 months ago

With conditional sends #1273, we maybe need the concept of an optional receive action.

The idea would be that if there is no message to receive, instead of the result being an error, the result is nil. This is for the case where the user knows that it is possible for there to be no message (perhaps from merging two things where the existence of one might depend on something in the message).

This is analogous to how m["x"] produces nil in the case where a m m has no field "x". Just as in this case, if the compiler determines that there will always be a message receivable, then nil would not be in the type of the expression.

A tool that generated a dataflow graph might generate optional receive actions by default.

hasithaa commented 9 months ago

Here is an example, that leads to this problem. https://github.com/hasithaa/Worker_Examples/blob/1fec1aa897aaa14201800d17c962fb412e01172e/HospitalService/main.bal#L62