This is an experimentation to lean implementing gRPC service to run JavaScript code in Rust with V8.
cargo run
time grpcurl \
-plaintext \
-import-path ./proto \
-proto service.proto \
-d '{"code": "1+1"}' \
'[::1]:50051' jsrunner.JSRunnerService/Run
while true; do grpcurl \
-plaintext \
-import-path ./proto \
-proto service.proto \
-d '{"code": "new Date()"}' \
'[::1]:50051' jsrunner.JSRunnerService/Run; sleep 1; done
CODE=$(cat <<EOF
var name = "dragon3"
var obj = {"name": name, "ts": new Date()};
obj;
EOF
)
grpcurl \
-plaintext \
-import-path ./proto \
-proto service.proto \
-d "$(jq -cn --arg code "${CODE}" '$ARGS.named')" \
'[::1]:50051' jsrunner.JSRunnerService/Run
CODE=$(cat <<EOF
var sum = 0;
for (var i = 0; i < 1e9; i++) {
sum += i;
}
sum;
EOF
)
grpcurl \
-plaintext \
-import-path ./proto \
-proto service.proto \
-d "$(jq -cn --arg code "${CODE}" '$ARGS.named')" \
'[::1]:50051' jsrunner.JSRunnerService/Run
CODE=$(cat <<EOF
var arr = [];
for (var i = 0; i < 1e7; i++) {
arr.push(new Array(1000).fill('a'));
}
arr.length;
EOF
)
grpcurl \
-plaintext \
-import-path ./proto \
-proto service.proto \
-d "$(jq -cn --arg code "${CODE}" '$ARGS.named')" \
'[::1]:50051' jsrunner.JSRunnerService/Run