libresilient/plugins/any-of
Michał 'rysiek' Woźniak b7419d0fe8 tests passing for work done so far for error handling improvements (ref. #36) 2024-03-06 16:33:22 +00:00
..
__tests__ tests passing for work done so far for error handling improvements (ref. #36) 2024-03-06 16:33:22 +00:00
README.md documenting plugins (ref. #51) 2022-05-17 23:36:08 +00:00
index.js renaming plugin and test files; plugins are now in individual subdirectories (ref. #50) 2022-05-15 18:53:04 +00:00

README.md

Plugin: any-of

The any-of composing plugin runs all plugins configured in its uses: configuration field simultaneously (using Promise.any()), and returns the firs successful response it receives.

In other words, it makes it possible to simultaneously try several different transport plugins, and return the response as soon as the first one succeeds.

Configuration

The any-of plugin supports the following configuration options:

  • uses (required)
    Array of objects, each object being in turn a configuration of a plugin. All configured plugins are used simultaneously to handle any fetch() requests, returning the first successful response received.

Performance and usability considerations

It is important to understand that using this plugin in conjunction with resource-intensive transport plugins might lead to a degraded performance in visitors' browsers, as all plugins configured for use by any-of will be processing the requests at the same time.

On the other hand, some transport plugins are slower than others while being more resilient to network issues. So using any-of and mixing slow-but-resilient transport plugins with fast-but-less-resilient ones might actually improve user experience: content is retrieved by the faster plugin when possible, otherwise it is retrieved by a slower plugin without waiting for the faster plugin to time out and only then starting the request using the slower one.

In the end, as is often the case, this is a balancing act.