Skip to content

Feature Request: support async fitting-factory #21

@osher

Description

@osher

Currently, the fittings are produced by a synchronous factory.
The factory is provided with fcty(fittingDef, bagpipes).

I would like to be able to introduce fittings that employ asynchronous initiation, and should be able to fail fast in the meaning of stop the process gracefully if any of their data-sources are not available.

A simplified example:

my-paramount-must-be-init-dal initiates itself with a map of values, and subscribes to a channel to be notified whenever they change. outside of it, any access to this map of values is synchronous.
The data-source and the subscription channels, are provided in fittingDef.dalCfg

const dal = require('./my-paramount-must-be-init-dal');
module.exports = myFittingFactory(fittingDef, bagpipes, cb) {
     dal.init(fittingDef.dalCfg, function(err) {
         if (err) return cb(err);
         cb( null, {  get: (id,cb) => cb(null, dal.repo[id]) } ) //not a mistake. sync access to object key
     })
}

To do this without asycn loading of the fitting I have to implement a deferring mechanism to each of the featured dal methods - and that's annoying... :/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions