Skip to content

Commit

Permalink
Fixed double-init issue.
Browse files Browse the repository at this point in the history
The first module's init/1 was being called in both start/3 and start/4. This can cause problems if init/1 has side effects.
  • Loading branch information
bluegraybox committed Oct 4, 2011
1 parent a34ae51 commit b15781e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/spooky.erl
Expand Up @@ -39,11 +39,14 @@ start(Modules) when is_list(Modules)->
start([Module|T], Handlers, Middlewares)->
?LOG_INFO("Starting spooky with ~p", [Module]),
% The first module's options are the ones for misultin
Opts = apply(Module, init, [[]]),

Opts0 = proplists:delete(handlers, Opts),
?LOG_INFO("Options ~p", [Opts]),
start([Module|T], Handlers, Middlewares, Opts0).
ModuleOpts = apply(Module, init, [[]]),

ModuleHandlers = lookup(handlers, ModuleOpts, [Module]),
ModuleMiddlewares = lookup(middlewares, ModuleOpts, []),

Opts = proplists:delete(handlers, ModuleOpts),
?LOG_INFO("Options ~p", [ModuleOpts]),
start(T, Handlers ++ ModuleHandlers, Middlewares ++ ModuleMiddlewares, Opts).

start([Module|T], Handlers, Middlewares, Opts)->
% Accumulate all the handlers and middlewares
Expand Down

0 comments on commit b15781e

Please sign in to comment.