Removing array element in foreach, safe?
Daniel Kozak via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Sep 5 10:38:10 PDT 2016
On Monday, 5 September 2016 at 15:53:39 UTC, dom wrote:
> is this code safe? if not how do i do it correctly?
>
> static AsyncHttpGet[] openRequests;
> static void updateRequests()
> {
> foreach(idx, req; openRequests)
> {
> if(req.state != Fiber.State.TERM)
> req.call();
> else
> openRequests.remove(idx);
> }
> }
>
> thx :)
openRequests = openRequests.filter!(a=>a.state !=
Fiber.State.TERM).array;
openRequests.each!((a){ a.call(); });
More information about the Digitalmars-d-learn
mailing list