text: /* globals coscript, sketch */
  var fiberAvailable = require('./test-if-fiber')
  
  var setTimeout
  var clearTimeout
  
  var fibers = []
  
  if (fiberAvailable()) {
    var fibers = []
  
    setTimeout = function (func, delay, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10) {
      // fibers takes care of keeping coscript around
      var id = fibers.length
      fibers.push(coscript.scheduleWithInterval_jsFunction(
        (delay || 0) / 1000,
        function () {
          func(param1, param2, param3, param4, param5, param6, param7, param8, param9, param10)
        }
      ))
      return id
    }
  
    clearTimeout = function (id) {
      var timeout = fibers[id]
      if (timeout) {
        timeout.cancel() // fibers takes care of keeping coscript around
        fibers[id] = undefined // garbage collect the fiber
      }
    }
  } else {
    setTimeout = function (func, delay, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10) {
      coscript.shouldKeepAround = true
      var id = fibers.length
      fibers.push(true)
      coscript.scheduleWithInterval_jsFunction(
        (delay || 0) / 1000,
        function () {
          if (fibers[id]) { // if not cleared
            func(param1, param2, param3, param4, param5, param6, param7, param8, param9, param10)
          }
          clearTimeout(id)
          if (fibers.every(function (_id) { return !_id })) { // if everything is cleared
            coscript.shouldKeepAround = false
          }
        }
      )
      return id
    }
  
    clearTimeout = function (id) {
      fibers[id] = false
    }
  }
  
  module.exports = {
    setTimeout: setTimeout,
    clearTimeout: clearTimeout
  }
  