       @push(newScope)
       result = f()
 
-      if f?.isFuture?
-        f.when => @pop()
+      if futures.future.isFuture(result)
         popLater = true
+        result.when => @pop()
 
       result
     finally

  # Only allow String, Numeric, Hash, Array, Proc, Boolean
  # or <tt>Liquid::Drop</tt>
  set: (key, value) ->
    @scopes[0][key] = value

  get: (key) ->
    @resolve(key)

  hasKey: (key) ->
    !!@resolve(key)


    variable or= @lookupAndEvaluate(scope, key)

    f = futures.future()
    delivered = false
    result = null

    Liquid.Helpers.unfuture variable, (err, variable) ->
      result = liquify(variable)
      f.deliver(err, result)
      delivered = true

    if delivered then result else f

  variable: (markup) ->
    future = futures.future()
