 
 (if define? then define else ((module) -> window.projectorHtml = module()))(->
+  waitForAll = (list, cb) ->
+    doneCount = 0
+
+    wait = ->
+      if list.length > doneCount
+        completion = (-> doneCount += 1; wait(); undefined)
+        list[doneCount].then completion, completion
+      else
+        cb()
+
+    wait()
+
   (viewModel, onRootElement) ->
     # defensive check
     throw 'must supply root element callback' if typeof onRootElement isnt 'function'

        # clean up previous DOM
        destroy()

        while startNode.nextSibling isnt endNode
          startNode.parentNode.removeChild startNode.nextSibling # @todo optimize using local vars

        # set up new DOM
        destroy = @scope ->
          @$projectorHtmlCursor = createCursor(currentDom, endNode)
          subTemplate.call(this, v)



    viewModel.region = (expr, subTemplate) ->
      destroy = (->)
      currentWaitList = []

      currentDom = @$projectorHtmlCursor()
      startNode = currentDom.ownerDocument.createComment('^')
