// Simple jamsh test demonstrating lifetime resource control and negotiation

function hello() {
  this.act = {
    init: function () { 
      log('START '+privilege()); 
      // negotiate more lifetime (default is 2000)
      log(negotiate('LIFE',10000))
      log(negotiate('SCHED',2000))
      // if negotiation was successful, we can sleep in peace, else..
    },
    compute : function () {
      var start=time();
      while(true) {
        if ((time()-start) > 1500) break;
      };
      log('Done');
    },
    stop: function () { log('STOP'); kill() }
  }
  this.trans = {
    init:"compute",
    compute:"stop",
  }
  this.on = {
    error: function (e,arg) { log('Error: '+e) },
  }
  this.next="init"
}

// default platform settings
config({
  IDLETIME:100,
  LIFETIME:Infinity,
  TIMESCHED:2000,
  TIMEPOOL:10000,
  RUNTIME:3000,
  LEVEL:2,
  verbose:3,
  "log+":'time',
})

compile(hello,{verbose:1})
start()

var id=create(hello,[])
