anchor.diff:      ?TRACE("~200p~nwpool: unknown message~n", [Msg]),
       State.
   
  -%% starts worker under the supervisor sup_wpool and also sets up a monitor. The
  -%% supvervisor does not restart the worker in case of failure. Its main purpose
  -%% is to shut workers down when scalaris is shuting down.
  -%% The monitor (between wpool and the worker) is used mainly for error
  -%% reporting. A link could also be used, but wpool would have to call
  -%% ``process_flag(trap_exit, true)'' for every link.
  +%% @doc start a worker
  +%%     starts worker under the supervisor sup_wpool and also sets up a monitor. The
  +%%     supvervisor does not restart the worker in case of failure. Its main purpose
  +%%     is to shut workers down when scalaris is shuting down.
  +%%     The monitor (between wpool and the worker) is used mainly for error
  +%%     reporting. A link could also be used, but wpool would have to call
  +%%     `process_flag(trap_exit, true)' for every link.
   -spec start_worker(comm:mypid(), job(), state()) -> state().
   start_worker(Source, Workload, State) ->
       Sup = pid_groups:get_my(sup_wpool),
  
positive.code: init([]) ->
      case config:read(wpool_js) of
          true ->
              application:start(sasl),
              application:start(erlang_js);
          _ ->
              ok
      end,
  
negative.code: work(DHTNodeGroup, {_Round, map, {jsanon, FunBin}, Data}) ->
      %% ?TRACE("worker: should apply ~p to ~p~n", [FunBin, Data]),
      {ok, VM} = js_driver:new(),
      return(DHTNodeGroup, lists:flatten([apply_js(FunBin, [X], VM) || X <- Data]));
  work(DHTNodeGroup, {_Round, reduce, {jsanon, FunBin}, Data}) ->
      {ok, VM} = js_driver:new(),
      return(DHTNodeGroup, apply_js(FunBin, [Data], VM)).
  
  %% @doc applies Fun with Args.
  -spec apply_erl(Fun::fun((Arg::term()) -> Res::A), Args::term()) -> A.
  apply_erl(Fun, Data) ->
      Fun(Data).
  
  %% @doc applies Fun with Args withing JSVM.
  -spec apply_js(Fun::binary(), Args::[term()], JSVM::port()) -> term().
  apply_js(FunBin, Data, VM) ->
      AutoJS = define_auto_js(FunBin, Data),
      {ok, Result} = js:eval(VM, AutoJS),
      Result.
  
  %% @doc create a self calling JS function.
  %%      takes a anonymous JS function (as a binary string) and a list of
  %%      arguments and returns a self calling JS (`function(arg) {...}(args)') 
  %%      function as a binary string.
  -spec define_auto_js(Fun::binary(), [term()]) -> binary().
  define_auto_js(FunBin, Args) ->
      EncodedArgs = encode_args(Args, []),
      iolist_to_binary([FunBin, "(", EncodedArgs, ")"]).
  
  %% @doc build argument list for JS function.
  %%      takes a list of terms and returns an iolist of the encoded (mochijson2)
  %%      terms with commas in between.
  -spec encode_args([term()], [term()]) -> term().
  encode_args([], Acc) ->
      lists:reverse(Acc);
  encode_args([H | []], Acc) ->
      encode_args([], [js_mochijson2:encode(H) | Acc]);
  encode_args([H | T], Acc) ->
      encode_args(T, [[js_mochijson2:encode(H), ","] | Acc]).
  
  %% send results back to wpool
  -spec return(pid_groups:groupname(), any()) -> ok.
  