Over the course of recent commits, `BackgroundWorker` and `ThreadPool`
have become more and more similar, and it got to the point where the
only difference was that `ThreadPool` was deliberately less convenient.
There's no good reason for `ThreadPool` to be this way, so this commit
removes the final difference.
It took a lot of work to get web workers to work, but web workers finally work!
`transferList` doesn't seem to work, though. It makes the object
inaccessible as expected, but it doesn't seem to affect performance.
Not well-tested yet, especially the web workers.
In addition to web workers, this completely rewrites both
`BackgroundWorker` and `ThreadPool`. It adds thread safety via the
`WorkOutput` object, adds flexibility by making `BackgroundWorker` build
off `ThreadPool`, and exposes an `eventSource` variable that tells
listeners which job dispatched a given event.
This improves the old web worker implementation by reusing the _entire_
JS file. This is slower but ensures that all classes are available,
simplifying the end user experience. Web workers are now forbidden from
using instance functions, which also simplifies things. And finally, the
code attempts to restore the prototypes of all class instances passed
across threads, though this relies on the exact way Haxe generates
JavaScript, and may not work in Haxe 3 or Haxe 5.
This actually makes `Future` more thread-safe than its parent classes.
Unfortunately `BackgroundWorker` and `ThreadPool` can't receive the same
treatment, as it'd break backward compatibility.
The `Future` constructor creates a new `Future` instance, and in other
news, this floor is made out of floor.
Since there's now so much more to read, we should cut out the blatantly
obvious parts.
Without this, if an error happened during a `ThreadPool` job, that
thread would exit without updating `currentThreads`.
This can almost replace `FutureWork`'s error handling, but not quite.
Modifying `onUpdate` is not thread safe, and must only be done on the
main thread. This is more important - and more enforceable - than most
of the "only do this on XYZ thread" comments.