Comments (9)
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.
I did experiment to see if events.on("nodes-started"){} might work but unfortunately not.
from node-red-nodes.
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.
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.
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.
yes, this would work. to be honest i liked my suggestion better ...
thanks for the example.
from node-red-nodes.
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.
actually that code need to break out of the loop once it gets the timeout error... :-)
from node-red-nodes.
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)
- node-red-node-email: authentication: none broken HOT 5
- select sqlite fail response
- Installation failed in latest node version above 18 HOT 1
- How can I disable the creation process? HOT 2
- Get datetime when qwery a date column HOT 2
- node-red-node-pi-gpio -> nrgpio.py uses ~1% CPU per IO port
- Node-red-node-email stops fetching GMail
- Gmail will soon require OAUTH credentials - "node-red-node-email" in jeopardy! HOT 4
- Node-red-node-email vulnerabilities HOT 6
- node-red-node-email unhelpful connect error HOT 4
- node-red-node-pushover support for attachment_base64 and attachment_type HOT 1
- mcp3xxx node does not seem to recognise raspberry pi on a pi4 running bookworm HOT 3
- Stomp node: error sending payload as XML
- node-red-node-serialport message duplication
- Issue with node-red-node-serialport and serial control Node: “TypeError: newline.substr is not a function” when Using Fixed Length Split Configuration HOT 3
- xmpp messages without type attribute can't be handled
- PiLCD: Startup warning "Raspberry Pi specific node set inactive" HOT 4
- node-red-node-ping always sends "false" in IPv4 Protocol setting HOT 9
- Email using long password and Authentication as TLS HOT 1
- node-red-node-pisrf needs updating to cope with replacement for RPi.GPIO
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-red-nodes.