seneca.js
function api_close(done) {
    var seneca = this

    var safe_done = _.once(function(err) {
      if (_.isFunction(done)) {
        return done.call(seneca, err)
      }
    })

    // don't try to close twice
    if (seneca.flags.closed) {
      return safe_done()
    }

    seneca.ready(do_close)
    var close_timeout = setTimeout(do_close, opts.$.close_delay)

    function do_close() {
      clearTimeout(close_timeout)

      if (seneca.flags.closed) {
        return safe_done()
      }

      // TODO: remove in 4.x
      seneca.closed = true

      seneca.flags.closed = true

      // cleanup process event listeners
      _.each(opts.$.system.close_signals, function(active, signal) {
        if (active) {
          process.removeListener(signal, private$.handle_close)
        }
      })

      seneca.log.debug({
        kind: 'close',
        notice: 'start',
        callpoint: callpoint()
      })

      seneca.act('role:seneca,cmd:close,closing$:true', function(err) {
        seneca.log.debug(errlog(err, { kind: 'close', notice: 'end' }))

        seneca.removeAllListeners('act-in')
        seneca.removeAllListeners('act-out')
        seneca.removeAllListeners('act-err')
        seneca.removeAllListeners('pin')
        seneca.removeAllListeners('after-pin')
        seneca.removeAllListeners('ready')

        seneca.private$.history.close()

        if (seneca.private$.status_interval) {
          clearInterval(seneca.private$.status_interval)
        }

        return safe_done(err)
      })
    }

    return seneca
  }
function api_close(done) {
    var seneca = this

    var safe_done = _.once(function(err) {
      if (_.isFunction(done)) {
        return done.call(seneca, err)
      }
    })

    // don't try to close twice
    if (seneca.flags.closed) {
      return safe_done()
    }

    seneca.ready(do_close)
    var close_timeout = setTimeout(do_close, opts.$.close_delay)

    function do_close() {
      clearTimeout(close_timeout)

      if (seneca.flags.closed) {
        return safe_done()
      }

      // TODO: remove in 4.x
      seneca.closed = true

      seneca.flags.closed = true

      // cleanup process event listeners
      _.each(opts.$.system.close_signals, function(active, signal) {
        if (active) {
          process.removeListener(signal, private$.handle_close)
        }
      })

      seneca.log.debug({
        kind: 'close',
        notice: 'start',
        callpoint: callpoint()
      })

      seneca.act('role:seneca,cmd:close,closing$:true', function(err) {
        seneca.log.debug(errlog(err, { kind: 'close', notice: 'end' }))

        seneca.removeAllListeners('act-in')
        seneca.removeAllListeners('act-out')
        seneca.removeAllListeners('act-err')
        seneca.removeAllListeners('pin')
        seneca.removeAllListeners('after-pin')
        seneca.removeAllListeners('ready')

        seneca.private$.history.close()

        if (seneca.private$.status_interval) {
          clearInterval(seneca.private$.status_interval)
        }

        return safe_done(err)
      })
    }

    return seneca
  }
function api_close ( done ) { var seneca = this var safe_done = _ . once ( function ( err ) { if ( _ . isFunction ( done ) ) { return done . call ( seneca , err ) } } ) // don't try to close twice if ( seneca . flags . closed ) { return safe_done ( ) } seneca . ready ( do_close ) var close_timeout = setTimeout ( do_close , opts . $ . close_delay ) function do_close ( ) { clearTimeout ( close_timeout ) if ( seneca . flags . closed ) { return safe_done ( ) } // TODO: remove in 4.x seneca . closed = true seneca . flags . closed = true // cleanup process event listeners _ . each ( opts . $ . system . close_signals , function ( active , signal ) { if ( active ) { process . removeListener ( signal , private$ . handle_close ) } } ) seneca . log . debug ( { kind : 'close' , notice : 'start' , callpoint : callpoint ( ) } ) seneca . act ( 'role:seneca,cmd:close,closing$:true' , function ( err ) { seneca . log . debug ( errlog ( err , { kind : 'close' , notice : 'end' } ) ) seneca . removeAllListeners ( 'act-in' ) seneca . removeAllListeners ( 'act-out' ) seneca . removeAllListeners ( 'act-err' ) seneca . removeAllListeners ( 'pin' ) seneca . removeAllListeners ( 'after-pin' ) seneca . removeAllListeners ( 'ready' ) seneca . private$ . history . close ( ) if ( seneca . private$ . status_interval ) { clearInterval ( seneca . private$ . status_interval ) } return safe_done ( err ) } ) } return seneca }
close seneca instance sets public seneca.closed property
close seneca instance sets public seneca . closed property