how to interrupt timeout long running method in nodejs?

Using the languages with built-in support for threads this seems to be be a fairly easy task but,

Is there any way to terminate/timeout a long running method / infinitely recursive method ?

For instance If I have an api that takes callback as argument, and does some processing before and after it's invocation and returns the result.

function api(data,callback) {
  processedData = before(data);
  result = callback(processedData);
  processedResult = after(result);
  return processedResult;
}

If the notorious developer calls this api with following callback

function cpuFrenzy(data) {
  while(true);
} 

result = api( {} , cpuFrenzy);
render(result);

and result of api is used to render HTML.

Node js being single threaded would block all requests to the server !

So is there any way for the api to timeout / terminate the callback method execution if it takes beyond some preset time, in order to avoid blocking all web requests?

If there is none, is there any other way to implement this api ?

Check tripwire: https://github.com/tjanczuk/tripwire