<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Thank you very much. With this explanation I should get my application properly limited.<br class=""><br class="">One thing though, is it not possible to get an error from jobs:ask/1 ? Like <span style="caret-color: rgb(110, 119, 129); color: rgb(110, 119, 129); font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace; white-space: pre; background-color: rgb(255, 255, 255);" class="">{error, Reason}</span><br class=""><div>when the queue is full? That is, jobs:done/1 have not been called for the previous 3  {ok, X}. <br class=""><br class="">bengt<br class=""><br class=""><blockquote type="cite" class=""><div class="">On 14 Nov 2021, at 19:55, Ulf Wiger <<a href="mailto:ulf@wiger.net" class="">ulf@wiger.net</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">In jobs, `max_size` has to do with how large the queue is allowed to get.<div class="">What you appear to be looking for is `counter`.<br class=""><br class="">Example:<br class="">Eshell V10.7.2.8  (abort with ^G)<br class="">1> application:ensure_all_started(jobs).<br class="">{ok,[jobs]}<br class="">2> jobs:add_queue(kalle, [{standard_counter,3}]).<br class="">ok<br class="">3> [spawn(fun() -> jobs:ask(kalle), io:fwrite("--> ~p: ~p~n", [time(), self()]), timer:sleep(3000), exit(normal) end) || _ <- lists:seq(1,10)].  <br class="">--> {19,53,29}: <0.128.0><br class="">--> {19,53,29}: <0.129.0><br class="">--> {19,53,29}: <0.130.0><br class="">[<0.128.0>,<0.129.0>,<0.130.0>,<0.131.0>,<0.132.0>,<br class=""> <0.133.0>,<0.134.0>,<0.135.0>,<0.136.0>,<0.137.0>]<br class="">--> {19,53,32}: <0.131.0><br class="">--> {19,53,32}: <0.133.0><br class="">--> {19,53,32}: <0.132.0><br class="">--> {19,53,35}: <0.134.0><br class="">--> {19,53,35}: <0.135.0><br class="">--> {19,53,35}: <0.136.0><br class="">--> {19,53,38}: <0.137.0><br class=""></div><div class=""><br class=""></div><div class="">From the docs:</div><div class="">"{standard_counter, C} - equivalent to [{regulators,[{counter,[{limit,C}, {modifiers,[{cpu,10},{memory,10}]}]}]}]"</div><div class=""><br class=""></div><div class="">(Usually, one doesn't specify the modifiers)</div><div class=""><br class=""></div><div class="">BR,</div><div class="">Ulf</div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Nov 13, 2021 at 6:12 PM bengt <<a href="mailto:cean.ebengt@gmail.com" class="">cean.ebengt@gmail.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Greetings,<br class="">
<br class="">
I would like to allow at most 3 processes to call a gen_server at the same time. I could check the message queue length, but why not use jobs (<a href="https://github.com/uwiger/jobs" rel="noreferrer" target="_blank" class="">https://github.com/uwiger/jobs</a>) ?<br class="">
<br class="">
Jobs is already in use by something I depend on, so it should be working. I test from the (iex) shell. As can be seen below I am making a mistake somewhere. Probably config, so how should I configure to only get 3 of the 5 jobs:ask/1 to be approved and queued? Or I have misunderstood the use, and an explanation of how to achieve the 3 caller limitation would be appreciated.<br class="">
<br class="">
 :jobs.add_queue(:kalle,  [{:max_size, 3}])<br class="">
  for _ <- [1,2,3,4,5], do: :jobs.ask(:kalle)<br class="">
  IO.inspect :jobs.queue_info(:kalle)<br class="">
<br class="">
   name: :kalle,<br class="">
   max_size: 3,<br class="">
   approved: 5,<br class="">
   queued: 5,<br class="">
   latest_dispatch: 378734152926266,<br class="">
   mod: :jobs_queue,<br class="">
   type: :fifo,<br class="">
   group: :undefined,<br class="">
   regulators: [],<br class="">
   max_time: :undefined,<br class="">
   check_interval: :infinity,<br class="">
   oldest_job: :undefined,<br class="">
   timer: :undefined,<br class="">
   link_ref: :undefined,<br class="">
   check_counter: 0,<br class="">
   empty: false,<br class="">
   depleted: false,<br class="">
   waiters: [],<br class="">
   stateful: :undefined,<br class="">
   st: {:st, #Reference<0.2285429207.3584425985.10312>},<br class="">
   producers: []<br class="">
<br class="">
Best Wishes,<br class="">
bengt</blockquote></div>
</div></blockquote></div><br class=""></body></html>