Giter VIP home page Giter VIP logo

Comments (9)

knolleary avatar knolleary commented on August 20, 2024

Hi

I think there is something to explore here.

I'm away from my laptop, so can't readily dig up examples, but some of our config nodes tackle this in different ways.

Some just provide shared config properties, with no functional code. It is left to the individual nodes to make use of the properties in whatever way makes sense.

Some represent a connection to an external system, and provide connection pooling. They also wrap the api such that it can always be called, regardless of the connection state. The async nature of node-red means messages can be flowing without everything connected etc. The MQTT connection, for example, allows subscriptions to be made even if not connected; they get buffered for when the connection is available.

Adding a node event would be another way if tackling it. But I want to think how this could be more widely applied. I'd rather a standard set of events over having node-specific events.

from node-red-nodes.

nzfarmer1 avatar nzfarmer1 commented on August 20, 2024

I did experiment to see if events.on("nodes-started"){} might work but unfortunately not.

from node-red-nodes.

dceejay avatar dceejay commented on August 20, 2024

as node.db only gets assigned within that same function can you not just check if it exists ? (I know it's not the node.js event style but... until we have a better plan)

from node-red-nodes.

nzfarmer1 avatar nzfarmer1 commented on August 20, 2024

thanks for your comment. do you have an example of how this would work? essentially i want to be able to make a db request during our node's init - at least prior to having this.on('input',...) invoked.

from node-red-nodes.

dceejay avatar dceejay commented on August 20, 2024

maybe something like...

        var i = 0;
        var chk = function() {
            if (!node.levelConfig.db) {
                i += 1;
                if (i >= 20) {
                    node.error("Database didn't connect"); // report some lack of database error after 10 secs
                }
                setTimeout( function() {
                    chk();
                }, 500); // check every 0.5 secs
            }
            else {
                // do something when we see database
            }
        }
        chk();

from node-red-nodes.

nzfarmer1 avatar nzfarmer1 commented on August 20, 2024

yes, this would work. to be honest i liked my suggestion better ...
thanks for the example.

from node-red-nodes.

knolleary avatar knolleary commented on August 20, 2024

Yes, an event based solution is much cleaner than having to poll. But at
least you can poll today until we get to doing this properly.

On Mon, 19 Jan 2015 18:58 Andrew McClure [email protected] wrote:

yes, this would work. to be honest i liked my suggestion better ...
thanks for the example.


Reply to this email directly or view it on GitHub
#90 (comment)
.

from node-red-nodes.

dceejay avatar dceejay commented on August 20, 2024

actually that code need to break out of the loop once it gets the timeout error... :-)

from node-red-nodes.

nzfarmer1 avatar nzfarmer1 commented on August 20, 2024

This adds backwards and hopefully forwards compatibility :)

    int i =0;
    this.dbChk = function() { // node <=> this
        if (!node.levelConfig.db) {
            i += 1;
            if (i >= 20) {
                node.error("Database didn't connect"); // report some lack of database error after 10 secs
                return;
            }
            setTimeout( function() {
                node.dbChk();
            }, 500); // check every 0.5 secs
        }
        else {
            node.levelConfig.emit('connect'); // Use existing handler.
        }
    }

    events.on("nodes-started",function(){
        node.dbChk();
    });

from node-red-nodes.

Related Issues (20)

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.