filecoin-project / orient

↻Observe-Orient-Decide-Act↩
MIT License
18 stars 6 forks source link

Don't capture loop variables in closure per-thread. #70

Closed porcuquine closed 4 years ago

porcuquine commented 4 years ago

Because a loop variable was being captured in closures run per-thread, sometimes the same input was being returned run multiple times when handling a solve-many request.

The solution is to explicitly pass the value to a new anonymous function taking it as an input. This effectively rebinds it to a fresh variable.

This PR adds a macro to do this and also one which abstracts the parallel mapping. The original code this replaces was written very quickly, so this should clean things up and fix some potential latent bugs.

Since this does end up changing a few things, it would be good to make sure it's still working as expected for consumers before merging. (cc: @nicola)