/* ========================================================================= *\ |* === Any-of: running multiple plugins simultaneously === *| \* ========================================================================= */ /** * this plugin does not implement any push method */ // no polluting of the global namespace please (function(LRPC){ // this never changes const pluginName = "any-of" LRPC.set(pluginName, (LR, init={})=>{ /* * plugin config settings */ // sane defaults let defaultConfig = { // list of plugins to run simultaneously plugins: [{ name: "alt-fetch" },{ name: "gun-ipfs" }] } // merge the defaults with settings from LibResilientConfig let config = {...defaultConfig, ...init} /** * getting content using regular HTTP(S) fetch() */ let fetchContent = (url) => { LR.log(pluginName, `using: [${config.plugins.map(p=>p.name).join(', ')}]!`) return Promise.any( config.plugins.map(p=>p.fetch(url)) ) } // and add ourselves to it // with some additional metadata return { name: pluginName, description: `Running simultaneously: [${config.plugins.map(p=>p.name).join(', ')}]`, version: 'COMMIT_UNKNOWN', fetch: fetchContent, uses: config.plugins } }) // done with not polluting the global namespace })(LibResilientPluginConstructors)