MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / loadPluginWithTimeout

Function loadPluginWithTimeout

src/lib/loadPlugins.js:129–163  ·  view source on GitHub ↗
(pluginId, justInstalled = false)

Source from the content-addressed store, hash-verified

127}
128
129export async function loadPluginWithTimeout(pluginId, justInstalled = false) {
130 const pluginState = { settled: false };
131 const pluginLoadPromise = loadPlugin(pluginId, justInstalled)
132 .catch(async (error) => {
133 pluginState.settled = true;
134 await markPluginBroken(pluginId, error);
135 throw error;
136 })
137 .then(async () => {
138 pluginState.settled = true;
139 await markPluginLoaded(pluginId, justInstalled);
140 });
141
142 try {
143 // Let app startup continue if a plugin is slow, but keep loading it in
144 // the background so good plugins on slower devices can still recover.
145 await Promise.race([
146 pluginLoadPromise,
147 new Promise((_, rej) =>
148 setTimeout(
149 () => rej(new PluginLoadTimeoutError()),
150 PLUGIN_LOAD_TIMEOUT,
151 ),
152 ),
153 ]);
154 return true;
155 } catch (error) {
156 if (error instanceof PluginLoadTimeoutError) {
157 markPluginTimedOut(pluginId, pluginState);
158 return false;
159 }
160
161 throw error;
162 }
163}
164
165async function markPluginLoaded(pluginId, justInstalled = false) {
166 LOADED_PLUGINS.add(pluginId);

Callers 2

installPluginFunction · 0.90
loadPluginsFunction · 0.85

Calls 4

loadPluginFunction · 0.85
markPluginBrokenFunction · 0.85
markPluginLoadedFunction · 0.85
markPluginTimedOutFunction · 0.85

Tested by

no test coverage detected