Last active
August 18, 2021 04:52
-
-
Save daneshk/30ba59524e08753169293424fea96791 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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