 	if !apps[appId]?
 		return Promise.resolve()
 	apps[appId] = apps[appId].then (url) ->
+		# ngrok must have been loaded already or we wouldn't have a url to disconnect from.
 		ngrok.disconnectAsync(url)
 		.then ->
 			# We throw an error so that `.start` will catch and restart the session.

Promise = require 'bluebird'
ngrok = Promise.promisifyAll require 'ngrok'
tty = Promise.promisifyAll require 'tty.js'
TypedError = require 'typed-error'

class DisconnectedError extends TypedError


apps = {}
nextPort = 81
exports.start = (app) ->
	init()
	apps[app.id] ?= Promise.rejected()
	return apps[app.id] = apps[app.id].catch ->
		port = nextPort++
