Giter VIP home page Giter VIP logo

Comments (5)

fredriks avatar fredriks commented on September 25, 2024

Happy New Year! 🎉

That would be very convenient to have, I like it!

What would be the use case to silently ignore rejections though? I imagine, at least in the scenarios I've used it, that it would be problematic if some variables failed to load (API keys, etc).

from cloud-functions-runtime-config.

DazWilkin avatar DazWilkin commented on September 25, 2024

Laziness :-(

It's unclear to me how to reconcile an array of Promises that contain resolves and rejects.

By ignoring rejects, the code is simpler... In my code currently, I have:

const getVariables = (runtimeConfig, config, variables) =>
    Promise
    .all(variables
        .map(variable => 
            runtimeConfig.getVariable(config, variable);
        )
        .map(p =>
            p.catch(() => undefined)
        )
    );

from cloud-functions-runtime-config.

fredriks avatar fredriks commented on September 25, 2024

Haha fair enough 😄

I like the idea of keeping it simple but as a library maybe we should leave the error handling to the user.

A user could handle it with a catch that is applied to getVariables. Using the mechanics of Promise.all; If all variables are loaded then is called with an array of the values. If not catch is called with the first rejection.

The API could look something like this:

runtimeConfig.getVariables('lunch-plans', ['monday', 'tuesday'])
    .then(values => {
        // this is executed if all values are loaded successfully
        // values: ['valueOfMonday', 'valueOfTuesday']
    })
    .catch(reason => {
        // this is called for the first variable that rejects
    });

This does not handle the case where, after some variable rejects, we still want to continue with the other variables but that might be out of scope here unless we can find a general way of dealing with that.

from cloud-functions-runtime-config.

fredriks avatar fredriks commented on September 25, 2024

Commit 3fc574b adds a method called getVariables as discussed above.

The interface is documented in README and it works as described above by wrappinggetVariable inside a call to Promise.all.

from cloud-functions-runtime-config.

DazWilkin avatar DazWilkin commented on September 25, 2024

Ah, you're good. Thank you!

from cloud-functions-runtime-config.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.