digitalmars.D.learn - Removing array element in foreach, safe?
- dom (13/13) Sep 05 2016 is this code safe? if not how do i do it correctly?
- Daniel Kozak (4/17) Sep 05 2016 openRequests = openRequests.filter!(a=>a.state !=
- Daniel Kozak (4/23) Sep 05 2016 or
- dom (2/21) Sep 05 2016 thx mate!
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 :)
Sep 05 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(); });
Sep 05 2016
On Monday, 5 September 2016 at 17:38:10 UTC, Daniel Kozak wrote:On Monday, 5 September 2016 at 15:53:39 UTC, dom wrote:or openRequests = openRequests.filter!(a=>a.state != 0).map!((a) {a.call(); return a;}).array;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(); });
Sep 05 2016
On Monday, 5 September 2016 at 17:38:10 UTC, Daniel Kozak wrote:On Monday, 5 September 2016 at 15:53:39 UTC, dom wrote:thx mate!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(); });
Sep 05 2016