-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
WebSocket close frame return type proposal discussion #1333
Comments
Is |
Yes, |
We have the
I believe we can address (2) by using integer singleton types and for (1), we can use a new field called
Sample: import ballerina/io;
// Object type to identify the predefined close frame types
public readonly distinct class PredefinedCloseFrameType {
};
// Object type to identify the custom close frame types
public readonly distinct class CustomCloseFrameType {
};
// Constant to represent the predefined close frame types
public final PredefinedCloseFrameType PREDEFINED_CLOSE_FRAME = new;
// Constant to represent the custom close frame types
public final CustomCloseFrameType CUSTOM_CLOSE_FRAME = new;
// Private record represents the common fields of the close frames
type CloseFrameBase record {|
readonly object {} 'type;
readonly int code;
anydata body;
|};
// Record to represent the normal closure close frame
public type NormalClosure record {|
*CloseFrameBase;
readonly PredefinedCloseFrameType 'type = PREDEFINED_CLOSE_FRAME;
readonly 1000 code = 1000;
|};
// Record to represent the custom close frame
public type CustomCloseFrame record {|
*CloseFrameBase;
readonly CustomCloseFrameType 'type = CUSTOM_CLOSE_FRAME;
|};
// Close frame type
public type CloseFrame NormalClosure|CustomCloseFrame;
public function main() {
NormalClosure normalClosure = {body: "Hello!"};
io:println(getType(normalClosure));
CustomCloseFrame customCloseFrame = {body: "Hello!", code: 2000};
io:println(getType(customCloseFrame));
}
function getType(CloseFrame closeFrame) returns string =>
closeFrame is CustomCloseFrame ? "custom" : (closeFrame is NormalClosure ? "normal" : "unknown"); |
Please use this issue to discuss the websocket close frame return type proposal.
The text was updated successfully, but these errors were encountered: