Skip to content

Instantly share code, notes, and snippets.

View daneshk's full-sized avatar

Danesh Kuruppu daneshk

View GitHub Profile
public function main() returns error? {
RouteGuideClient ep = check new ("http://localhost:8980");
RouteNote[] routeNotes = [
{location: {latitude: 406109563, longitude: -742186778}, message: "m1"},
{location: {latitude: 411733222, longitude: -744228360}, message: "m2"}
];
RouteChatStreamingClient routeClient = check ep->RouteChat();
service "RouteGuide" on new grpc:Listener(8980) {
remote function RouteChat(RouteGuideRouteNoteCaller caller,
stream<RouteNote, grpc:Error?> clientNotesStream) returns error? {
check clientNotesStream.forEach(function(RouteNote receivedNote) {
string pointKey = keyFromPoint(receivedNote.location);
lock {
RouteNote[]? routeNotes = ROUTE_NOTES_MAP[pointKey];
if routeNotes is RouteNote[] {
foreach RouteNote sendNote in routeNotes {
service RouteGuide {
rpc RouteChat(stream RouteNote) returns (stream RouteNote) {}
}
RouteGuideClient ep = check new ("http://localhost:8980");
// Client streaming
Point[] points = [
{latitude: 406109563, longitude: -742186778},
{latitude: 411733222, longitude: -744228360}
];
RecordRouteStreamingClient recordRouteStrmClient = check ep->RecordRoute();
foreach Point p in points {
check recordRouteStrmClient->sendPoint(p);
service "RouteGuide" on new grpc:Listener(8980) {
remote function RecordRoute(stream<Point, grpc:Error?> clientStream) returns RouteSummary|error {
Point? lastPoint = ();
int pointCount = 0;
int featureCount = 0;
int distance = 0;
decimal startTime = time:monotonicNow();
error? e = clientStream.forEach(function(Point p) {
service RouteGuide {
rpc RecordRoute(stream Point) returns (RouteSummary) {}
}
RouteGuideClient ep = check new ("http://localhost:8980");
// Server streaming
Rectangle rectangle = {
lo: {latitude: 400000000, longitude: -750000000},
hi: {latitude: 420000000, longitude: -730000000}
};
stream<Feature, grpc:Error?> features = check ep->ListFeatures(rectangle);
error? e = features.forEach(function(Feature f) {
service "RouteGuide" on new grpc:Listener(8980) {
remote function ListFeatures(Rectangle rectangle) returns stream<Feature, grpc:Error?>|error {
int left = int:min(rectangle.lo.longitude, rectangle.hi.longitude);
int right = int:max(rectangle.lo.longitude, rectangle.hi.longitude);
int top = int:max(rectangle.lo.latitude, rectangle.hi.latitude);
int bottom = int:min(rectangle.lo.latitude, rectangle.hi.latitude);
Feature[] selectedFeatures = from var feature in FEATURES
where feature.name != ""
service RouteGuide {
rpc ListFeatures(Rectangle) returns (stream Feature) {}
}
RouteGuideClient ep = check new ("http://localhost:8980");
Feature feature = check ep->GetFeature({latitude: 406109563, longitude: -742186778});
io:println(`GetFeature: lat=${feature.location.latitude}, lon=${feature.location.longitude}`);