mchidk/BinaryRage — pull request #10 by tormaroe (2013-06-29 16:03:52+00:00)
Title: Added DB.WaitForCompletion() - waits for all writes to complete

My biggest concern with BinaryRage so far has been that it does not complete pending writes if the process is terminated. I've had to add Thread.Sleep() calls to fix this - both in automated tests and in my apps.

This pull request is a suggestion on how to fix this quite easily by keeping track of the number of non-completed write tasks. It's the first time I've used CountdownEvent, so I'm not sure this is fool-proof, but it seems to do the job (see the test).

One problem will be if DB.Insert() is called from multiple threads - CountdownEvent.Reset() is not thread safe. Is Insert() intended to be thread safe?