mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 00:13:13 +09:00
Add waitForPlugin and load plugins concurrently
Plugins can wait for another plugin on the same controller, host or instance with waitForPlugin(waiter, name, timeoutMs). It resolves to what the other plugin's entrypoint returned, or to undefined with a warning naming both plugins if it is not loaded once loading finishes or the timeout runs out. Plugin entrypoints now run concurrently so a plugin can await a plugin later in the list from its entrypoint. loadedPlugins is still filled in plugin list order, as the instance builds its Lua module list from it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
eefb4be44b
commit
c8e52e7bde
12 files changed
+408
-29
No files matched your search
@@ -185,6 +185,7 @@ describe("lib/plugin_loader", function() {
|
||||
await writeEntrypoint(functionPlugin, `
|
||||
export default async function(context) {
|
||||
context.controller.loadedWith = context;
|
||||
return { api: true };
|
||||
}
|
||||
`);
|
||||
await writeEntrypoint(classPlugin, `
|
||||
@@ -231,7 +232,10 @@ describe("lib/plugin_loader", function() {
|
||||
});
|
||||
it("should call the default export with the load context", async function() {
|
||||
const pluginInfo = info(functionPlugin);
|
||||
await lib.loadPlugin(pluginInfo, "controller", context, "ControllerPlugin", BaseControllerPlugin);
|
||||
const result = await lib.loadPlugin(
|
||||
pluginInfo, "controller", context, "ControllerPlugin", BaseControllerPlugin,
|
||||
);
|
||||
assert.deepEqual(result, { api: true });
|
||||
assert.equal(controller.loadedWith.controller, controller);
|
||||
assert.equal(controller.loadedWith.plugin, pluginInfo);
|
||||
assert.equal(controller.loadedWith.logger, logger);
|
||||
@@ -239,7 +243,10 @@ describe("lib/plugin_loader", function() {
|
||||
});
|
||||
it("should load a deprecated class export", async function() {
|
||||
const pluginInfo = info(classPlugin);
|
||||
await lib.loadPlugin(pluginInfo, "controller", context, "ControllerPlugin", BaseControllerPlugin);
|
||||
const result = await lib.loadPlugin(
|
||||
pluginInfo, "controller", context, "ControllerPlugin", BaseControllerPlugin,
|
||||
);
|
||||
assert.equal(result, controller.loadedWith);
|
||||
assert(controller.loadedWith instanceof BaseControllerPlugin);
|
||||
assert.equal(controller.loadedWith.info, pluginInfo);
|
||||
assert.deepEqual([...controller.hooks.save.attached], ["test"]);
|
||||
|
||||
Reference in new issue
Block a user