aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ssh/src/ssh_options.erl
diff options
context:
space:
mode:
authorHans Nilsson <[email protected]>2017-04-06 19:31:13 +0200
committerHans Nilsson <[email protected]>2017-04-07 10:19:56 +0200
commit4d6393bc4df58defbc22c5d97e28bbfdd8794fc6 (patch)
tree37f2957737075a567d05412e9ff0156a88c6182e /lib/ssh/src/ssh_options.erl
parent3bbb2c9d5f92205f91cc68b9cebe263b84afe3e2 (diff)
downloadotp-4d6393bc4df58defbc22c5d97e28bbfdd8794fc6.tar.gz
otp-4d6393bc4df58defbc22c5d97e28bbfdd8794fc6.tar.bz2
otp-4d6393bc4df58defbc22c5d97e28bbfdd8794fc6.zip
ssh: Lazy default in get options macro
Diffstat (limited to 'lib/ssh/src/ssh_options.erl')
-rw-r--r--lib/ssh/src/ssh_options.erl15
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/ssh/src/ssh_options.erl b/lib/ssh/src/ssh_options.erl
index febd3f6eef..ee3cdbb8a0 100644
--- a/lib/ssh/src/ssh_options.erl
+++ b/lib/ssh/src/ssh_options.erl
@@ -69,17 +69,20 @@ get_value(Class, Key, Opts, _CallerMod, _CallerLine) ->
error({bad_options,Class, Key, Opts, _CallerMod, _CallerLine}).
--spec get_value(option_class(), option_key(), options(), any(),
+-spec get_value(option_class(), option_key(), options(), fun(() -> any()),
atom(), non_neg_integer()) -> any() | no_return().
-get_value(socket_options, Key, Opts, Def, _CallerMod, _CallerLine) when is_map(Opts) ->
- proplists:get_value(Key, maps:get(socket_options,Opts), Def);
-get_value(Class, Key, Opts, Def, CallerMod, CallerLine) when is_map(Opts) ->
+get_value(socket_options, Key, Opts, DefFun, _CallerMod, _CallerLine) when is_map(Opts) ->
+ proplists:get_value(Key, maps:get(socket_options,Opts), DefFun);
+get_value(Class, Key, Opts, DefFun, CallerMod, CallerLine) when is_map(Opts) ->
try get_value(Class, Key, Opts, CallerMod, CallerLine)
+ of
+ undefined -> DefFun();
+ Value -> Value
catch
- error:{badkey,Key} -> Def
+ error:{badkey,Key} -> DefFun()
end;
-get_value(Class, Key, Opts, _Def, _CallerMod, _CallerLine) ->
+get_value(Class, Key, Opts, _DefFun, _CallerMod, _CallerLine) ->
error({bad_options,Class, Key, Opts, _CallerMod, _CallerLine}).