-5

I am using node.js. I want to do something like the following:

 if (execution of foo() takes at most 30s) {
    var X = value returned by foo();
 } else {
    console.log('foo() took too long');
 }

How can I do this?

nigel
  • 197
  • 1
  • 10
  • 3
    Check this out: https://stackoverflow.com/a/30940189/1823841 – palaѕн Mar 09 '18 at 15:06
  • 2
    It looks like you want us to write some code for you. While many users are willing to produce code for a coder in distress, they usually only help when the poster has already tried to solve the problem on their own. A good way to demonstrate this effort is to include the code you've written so far, example input (if there is any), the expected output, and the output you actually get (console output, tracebacks, etc.). The more detail you provide, the more answers you are likely to receive. Check the [FAQ] and [ask]. – Clijsters Mar 09 '18 at 15:18

1 Answers1

-2

You can execute your function during 30 seconde in this line. Then it is cut down.

var X = setTimeOut(foo(){return 0}, 30000)

So you don't need information of timeout in console.log