5 comments

[ 39.8 ms ] story [ 785 ms ] thread
I like it - sounds crazy but (could be :) brilliant.

I suppose there's nothing stopping me from sending an infinite loop "query"?

  func(async () => while(true) {})
Ah, I see it - watching on tick/setImmediate for functions that take too long. Nice!

It's an intriguing concept, I'll be sure to study what you've created and explore its possibilities. There are many aspects I like about it, like being able to use modern JavaScript to fetch/query/filter from the client.

Watchdog algorithm explained:

The Runner receivers JS code, I wrote a babel plugin [1] to insert watchdog checks inside each loop (for, while, dowhile), also in each arrow function, that checks each time a function executes.

If the check scope is async, the watchdog awaits for a Promise that resolves immediately to give the opportunity to other functions in the thread, this function collaborative, does not hijack nodejs thread, so, it is allowed to run 10 minutes default.

If the scope is not async, the nodejs thread can be hijacked, so, it is allowed to run 100 milliseconds.

The watchdog stops the function by throwing a TimeoutError if the time is consumed in each case.

Finally, a check in inserted on each `catch`, and `finally` statements for the following cases:

    try {
      // infinite loop
    } catch(e) {
      // infinite loop
    } finally {
      // infinite loop
    }
[1] https://github.com/yosbelms/remote-func/blob/master/server/f...
Wow! Thank you so much for the explanation. This is indeed treating it as a query language.

I had originally thought this library is basically eval + Proxy, an approach I had explored before a bit, for running user-written scripts. Funny enough, I've also gone down the road of developing a mini-language, which has a check on each parsed instruction, to have detailed control of its execution.

I didn't realize the "remote function" gets parsed and transpiled on the server.

Using a custom Babel plugin to transform the source, placing a check on each step, that is genius.

Oh, and I see there's an in-memory cache, using the source itself as a Map hash. Practical.

Seeing the depth of thought that's gone into it, I really think you are onto something with this. It deserves more attention than it's gotten so far. I'm sure many people love this kind of meta-level language wizardry.