<div dir="ltr"><div dir="ltr">On Mon, Nov 9, 2020 at 9:50 PM rinfz via Digitalmars-d-learn <<a href="mailto:digitalmars-d-learn@puremagic.com">digitalmars-d-learn@puremagic.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Monday, 9 November 2020 at 20:40:59 UTC, rinfz wrote:<br>
> On Monday, 9 November 2020 at 19:55:07 UTC, Vino wrote:<br>
>> ...<br>
><br>
> The only curl option you need to set within the loop is the <br>
> CurlOption.url. So your foreach block should look more like:<br>
><br>
> foreach (...) {<br>
>Â Â Â string url = chain(apihost, only(':'), to!string(apiport), <br>
> apiuri).to!string;<br>
>Â Â Â https.handle.set(CurlOption.url, url);<br>
>Â Â Â https.perform();<br>
>Â Â Â scope(failure) exit(-4);<br>
>Â Â Â scope(exit) https.shutdown;<br>
>Â Â Â apidata.insert(tuple(seq, cast(string) content));<br>
>Â Â Â content = [];<br>
> }<br>
><br>
> Every other line can be placed before the foreach.<br>
<br>
In fact, you don't need url in there either since it's not <br>
dependent on loop variables, and you don't need the scope guards <br>
if this is running in main (you can move them out of the loop <br>
too).<br>
<br>
foreach (...) {<br>
   https.handle.set(CurlOption.url, url);<br>
   https.perform();<br>
   apidata.insert(tuple(seq, cast(string) content));<br>
   content = [];<br>
}<br></blockquote><div><br></div><div>In fact he does not need foreach. Because he use it on empty result </div></div></div>