<commit_before>%% -------------------------------------------------------------------
%%
%% Copyright (c) 2007-2010 Basho Technologies, Inc.  All Rights Reserved.
%%
%% -------------------------------------------------------------------

-module(riak_sock_pool).

-behaviour(gen_server).

%% API
-export([start_link/3, checkout/1, checkin/2, current_count/1]).

%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
         terminate/2, code_change/3]).
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-export([new_conn/0]). % for unit testing
-endif.

-define(MAX_RETRY_WAIT, 250).

-record(state, {pool=[],
                openmod,
                closemod,
                countfun,
                initialized=false}).

%% thanks to <NAME> for the idea
-record('DOWN',
	{
	  ref,   %% monitor reference
	  type,  %% type of object 'process'
	  id,    %% object id (pid)
	  reason %% reason for termination
	 }).

start_link(Name, ConnMod, CountFun) ->
    gen_server:start_link({local, Name}, ?MODULE, [ConnMod, CountFun], []).

checkout(Name) ->
    case gen_server:call(Name, checkout) of
        empty_pool ->
            timer:sleep(random:uniform(?MAX_RETRY_WAIT)),
            checkout(Name);
        R ->
            R
    end.

checkin(Name, Conn) ->
    gen_server:cast(Name, {checkin, Conn}).

current_count(Name) ->
    gen_server:call(Name, current_count).
<commit_msg>Add infinity timeout to riak_sock_pool server calls<commit_after>%% -------------------------------------------------------------------
%%
%% Copyright (c) 2007-2010 Basho Technologies, Inc.  All Rights Reserved.
%%
%% -------------------------------------------------------------------

-module(riak_sock_pool).

-behaviour(gen_server).

%% API
-export([start_link/3, checkout/1, checkin/2, current_count/1]).

%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
         terminate/2, code_change/3]).
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-export([new_conn/0]). % for unit testing
-endif.

-define(MAX_RETRY_WAIT, 250).

-record(state, {pool=[],
                openmod,
                closemod,
                countfun,
                initialized=false}).

%% thanks to <NAME> for the idea
-record('DOWN',
	{
	  ref,   %% monitor reference
	  type,  %% type of object 'process'
	  id,    %% object id (pid)
	  reason %% reason for termination
	 }).

start_link(Name, ConnMod, CountFun) ->
    gen_server:start_link({local, Name}, ?MODULE, [ConnMod, CountFun], []).

checkout(Name) ->
    case gen_server:call(Name, checkout, infinity) of
        empty_pool ->
            timer:sleep(random:uniform(?MAX_RETRY_WAIT)),
            checkout(Name);
        R ->
            R
    end.

checkin(Name, Conn) ->
    gen_server:cast(Name, {checkin, Conn}).

current_count(Name) ->
    gen_server:call(Name, current_count, infinity).

{'fraction_non_alphanumeric': 0.23039889958734525, 'fraction_numerical': 0.015130674002751032, 'mean_word_length': 2.039707419017764, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1359431', 'n_tokens_mistral': 957, 'n_tokens_neox': 889, 'n_words': 188}