Permalink
Browse files

Add spawn_opt option for open and open_link.

Typically used to specify non-default, garbage collection options.
  • Loading branch information...
norton committed Sep 25, 2012
1 parent 1bbea4b commit 4023ecf01351e2eeae84053bfa6f5e02debd1247
Showing with 13 additions and 6 deletions.
  1. +9 −4 src/hanoidb.erl
  2. +4 −2 src/hanoidb_level.erl
View
@@ -69,6 +69,7 @@
| {merge_strategy, fast | predictable }
| {sync_strategy, none | sync | {seconds, pos_integer()}}
| {expiry_secs, non_neg_integer()}
+ | {spawn_opt, list()}
.
%% @doc
@@ -83,14 +84,16 @@ open(Dir) ->
- spec open(Dir::string(), Opts::[config_option()]) -> {ok, hanoidb()} | ignore | {error, term()}.
open(Dir, Opts) ->
ok = start_app(),
- gen_server:start(?MODULE, [Dir, Opts], []).
+ SpawnOpt = hanoidb:get_opt(spawn_opt, Opts, []),
+ gen_server:start(?MODULE, [Dir, Opts], [{spawn_opt,SpawnOpt}]).
%% @doc Create or open a hanoidb store with a registered name.
- spec open(Name::{local, Name::atom()} | {global, GlobalName::term()} | {via, ViaName::term()},
Dir::string(), Opts::[config_option()]) -> {ok, hanoidb()} | ignore | {error, term()}.
open(Name, Dir, Opts) ->
ok = start_app(),
- gen_server:start(Name, ?MODULE, [Dir, Opts], []).
+ SpawnOpt = hanoidb:get_opt(spawn_opt, Opts, []),
+ gen_server:start(Name, ?MODULE, [Dir, Opts], [{spawn_opt,SpawnOpt}]).
%% @doc
%% Create or open a hanoidb store as part of a supervision tree.
@@ -105,15 +108,17 @@ open_link(Dir) ->
- spec open_link(Dir::string(), Opts::[config_option()]) -> {ok, hanoidb()} | ignore | {error, term()}.
open_link(Dir, Opts) ->
ok = start_app(),
- gen_server:start_link(?MODULE, [Dir, Opts], []).
+ SpawnOpt = hanoidb:get_opt(spawn_opt, Opts, []),
+ gen_server:start_link(?MODULE, [Dir, Opts], [{spawn_opt,SpawnOpt}]).
%% @doc Create or open a hanoidb store as part of a supervision tree
%% with a registered name.
- spec open_link(Name::{local, Name::atom()} | {global, GlobalName::term()} | {via, ViaName::term()},
Dir::string(), Opts::[config_option()]) -> {ok, hanoidb()} | ignore | {error, term()}.
open_link(Name, Dir, Opts) ->
ok = start_app(),
- gen_server:start_link(Name, ?MODULE, [Dir, Opts], []).
+ SpawnOpt = hanoidb:get_opt(spawn_opt, Opts, []),
+ gen_server:start_link(Name, ?MODULE, [Dir, Opts], [{spawn_opt,SpawnOpt}]).
%% @doc
%% Close a Hanoi data store.
View
@@ -80,12 +80,14 @@ debug_log(State,Fmt,Args) ->
open(Dir,Level,Next,Opts,Owner) when Level>0 ->
hanoidb_util:ensure_expiry(Opts),
- PID = plain_fsm:spawn(?MODULE,
+ SpawnOpt = hanoidb:get_opt(spawn_opt, Opts, []),
+ PID = plain_fsm:spawn_opt(?MODULE,
fun() ->
process_flag(trap_exit,true),
link(Owner),
initialize(#state{dir=Dir,level=Level,next=Next,opts=Opts,owner=Owner})
- end),
+ end,
+ SpawnOpt),
{ok, PID}.
lookup(Ref, Key) ->

0 comments on commit 4023ecf

Please sign in to comment.