mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-09 09:30:10 +08:00
WebWorkers: Allow native modules to be notified when executors are unregistered
Summary: This will allow them to clean up resources when a web worker goes away. Reviewed By: mhorowitz, lexs Differential Revision: D2994721 fb-gh-sync-id: c7ca1afc7290e85038cf692a139f6478dba0ef61 shipit-source-id: c7ca1afc7290e85038cf692a139f6478dba0ef61
This commit is contained in:
committed by
Facebook Github Bot 3
parent
1bab7c5182
commit
6d5f9ddfff
@@ -30,6 +30,7 @@ public class NativeModuleRegistry {
|
||||
private final List<ModuleDefinition> mModuleTable;
|
||||
private final Map<Class<? extends NativeModule>, NativeModule> mModuleInstances;
|
||||
private final ArrayList<OnBatchCompleteListener> mBatchCompleteListenerModules;
|
||||
private final ArrayList<OnExecutorUnregisteredListener> mOnExecutorUnregisteredListenerModules;
|
||||
|
||||
private NativeModuleRegistry(
|
||||
List<ModuleDefinition> moduleTable,
|
||||
@@ -37,12 +38,16 @@ public class NativeModuleRegistry {
|
||||
mModuleTable = moduleTable;
|
||||
mModuleInstances = moduleInstances;
|
||||
|
||||
mBatchCompleteListenerModules = new ArrayList<OnBatchCompleteListener>(mModuleTable.size());
|
||||
mBatchCompleteListenerModules = new ArrayList<>(mModuleTable.size());
|
||||
mOnExecutorUnregisteredListenerModules = new ArrayList<>(mModuleTable.size());
|
||||
for (int i = 0; i < mModuleTable.size(); i++) {
|
||||
ModuleDefinition definition = mModuleTable.get(i);
|
||||
if (definition.target instanceof OnBatchCompleteListener) {
|
||||
mBatchCompleteListenerModules.add((OnBatchCompleteListener) definition.target);
|
||||
}
|
||||
if (definition.target instanceof OnExecutorUnregisteredListener) {
|
||||
mOnExecutorUnregisteredListenerModules.add((OnExecutorUnregisteredListener) definition.target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,6 +140,12 @@ public class NativeModuleRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
public void onExecutorUnregistered(ExecutorToken executorToken) {
|
||||
for (int i = 0; i < mOnExecutorUnregisteredListenerModules.size(); i++) {
|
||||
mOnExecutorUnregisteredListenerModules.get(i).onExecutorDestroyed(executorToken);
|
||||
}
|
||||
}
|
||||
|
||||
public <T extends NativeModule> T getModule(Class<T> moduleInterface) {
|
||||
return (T) Assertions.assertNotNull(mModuleInstances.get(moduleInterface));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user