WebWorkers: implement tear down and terminate()

Summary:
public
Previously we did no cleanup when the executor was torn down and didn't expose a way to tear down the worker from JS. Now we do.

Termination happens synchronously and waits the the worker's MessageQueueThread to finish and join.

Reviewed By: mhorowitz

Differential Revision: D2815240

fb-gh-sync-id: 786beb30d4d64556586b91727f32e379c667a965
This commit is contained in:
Andy Street
2016-01-12 04:51:16 -08:00
committed by facebook-github-bot-4
parent b0519c8280
commit 0be36a2c80
8 changed files with 145 additions and 12 deletions

View File

@@ -43,4 +43,11 @@ public interface MessageQueueThread {
* {@link AssertionError}) if the assertion fails.
*/
void assertIsOnThread();
/**
* Quits this MessageQueueThread. If called from this MessageQueueThread, this will be the last
* thing the thread runs. If called from a separate thread, this will block until the thread can
* be quit and joined.
*/
void quitSynchronous();
}

View File

@@ -101,6 +101,7 @@ public class MessageQueueThreadImpl implements MessageQueueThread {
* Quits this queue's Looper. If that Looper was running on a different Thread than the current
* Thread, also waits for the last message being processed to finish and the Thread to die.
*/
@Override
public void quitSynchronous() {
mIsFinished = true;
mLooper.quit();