   # If a klass is given, construct a new one; otherwise, just return
   # the raw value.
   build: (value, klass) ->
+    klass ?= @wrapper_class
     if klass? then @bless(new klass(value)) else value
   
   # Extend the given object with the context methods of a worker,

  emit: (args..., value) ->
    @emitted = true
    key = args.join consts.arg_sep
    @db.set key, JSON.stringify(value)
    @db.publish @resp_channel, key

  # If we've seen this `@for_reals` before, then blow right past it.

  # The dispatcher said to resume, so go look for the missing values again.
  resume: ->
    @get_deps true
  
  # Set the default wrapper class, which is overridden by `as: `
  wrapper: (klass) ->
    @wrapper_class = klass


# Extend the blessed methods with the given ones, so that
# worker contexts can use them.
Worker.mixin = (mixins) ->
  _.extend (Worker.mixins ?= {}), mixins
  _.extend Worker.prototype, mixins

module.exports =
  
