Skip to content

Instantly share code, notes, and snippets.

@daneshk
Last active August 18, 2021 04:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daneshk/30ba59524e08753169293424fea96791 to your computer and use it in GitHub Desktop.
Save daneshk/30ba59524e08753169293424fea96791 to your computer and use it in GitHub Desktop.
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) {
pointCount += 1;
if pointExistsInFeatures(FEATURES, p) {
featureCount += 1;
}
if lastPoint is Point {
distance += calculateDistance(<Point>lastPoint, p);
}
lastPoint = p;
});
decimal endTime = time:monotonicNow();
int elapsedTime = <int>(endTime - startTime);
return {point_count: pointCount, feature_count: featureCount, distance: distance, elapsed_time: elapsedTime};
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment