I have a requirement where server method needs to be called continuously in the same way as clients continuously listen to subscribed events and get notified on any trigger.
Having a button to initiate server event doesn't meet the requirement like in the following example because the client needs to update its location continuously in the database (assuming that it is moving).
$('#btnSubmit').click(function (e) {
myChatHub.server.broadcastMessageToAll("Peace", 'World');
});
Initially, I thought of using a timer which ticks in every 2-3 minutes, but I am sure there is a better way to do it in SignalR.
Please suggest me the right way to do so.
Related
If I do not use .off() in particular to shut down the event listener, will it be turned off automatically when the http request has been processed?
So when a user browses http://www.example.com/organisations and I retrieve the data with an .on() call like:
admin.database().ref('organisations').on('child_added', snap...)
What happens with that connection when the request is done and the user got his data? Since I don't close the event listener with .off() I should assume Cloud Functions is still listening to the child_added event? But on the other hand that wouldn't make any sense for an http-request, so I could also assume that Firebase closes all event listeners after the request has been processed?
If you don't call off() to stop a listener that was started by on(), it will not turn off. You may be billed for the bandwidth it consumes until the allocated server instance shuts down.
Use of on() in Cloud Functions is almost never the right thing to do.
You should probably just be calling once() at the location of your data and use it when it's ready.
I wrote some code for sending an async request via ipc in electron, but I wanna know that how can I abort or cancel the ipc requests which I already sent out.
ipc.on('receivedSoftwareInfo', (info) => {
// TO-DO
});
ipc.send('getSoftwareInfo');
I had searched the api documents from Repo of electron, and got an information that I can stop by invoking removeListener like following code so that events I bind won't trigger.
ipc.removeAllListeners();
But I think there is a potential problem if user click the button and request again immediately, it will remove all of listener by program's side, then ipc send request second time.
It will look like following flow:
Events are removed -> async request is still there -> bind events again -> trigger
(I don't want it happen and trigger by old request)
So, is there any way to abort an ipc async request sending in electron? I think it's better than removing all of listeners to solve this question.
Unfortunaly, that is not possible. An IPC request is managed by the browser (here, Electron) and cannot be managed in JavaScript.
I'm just getting started with Meteor and I have a REST API hooked up with publish / subscribe that can periodically update per client. How do I run this behavior once globally and only refresh as long as a client is connected?
My first use case is periodically refreshing content while clients are active. My second use case is having some kind of global lock to make sure a task is only happening once at a time. I'm trying to use Meteor to make a deployment UI and I only want 1 deployment to happen at once.
publish/subscribe will work automatically only when clients are connected. However, do not put any functionality that you want to control amount of execution times in publish or subscribe functions. They might run arbitrary amount of times.
If you want some command to be executed by any client use Meteor.methodss on server side, and call it explicitly with Meteor.call from client template event.
To make sure that only one deployment happens at any given time, simplest way would be to create another collection, called for example, CurrentDeployments.And any time deployment script function in Meteor.methods is executed, check with CurrentDeployments.findOne if there are ongoing deployment or not, and only call new one if none is running.
As a side bonus, subscribe to CurrentDeployments in client, to disable 'deploy' button in case one is already running.
New to firebase and trying to understand how things work. I have an android app and plan to use the offline support and I'm trying to figure out whether or not I need to use callbacks. When I make a call like:
productNode.child("price").setValue(product.price)
Does that call to setValue happen synchronously on the main thread and the sync to the cloud happens asynchronously? Or does both execute asynchronously on a background thread?
The Firebase client immediately updates its local copy of the data with the new value. As part of this it fires any local (value, child_*) events that are needed.
Sending of the data to the database happens on a separate thread. If you want to know when this has completed, you can register a CompletionListener.
If the server somehow cannot complete the write operation (typically because the write violates a security rule), the client will fire any additional events that are needed to get the app back into the correct state. So in the case of a value listener it will then fire a second value event with the previous value.
I'm trying to understand how netty works, and after reading some of the documentation I was to see if I understood how things work at a high level.
Basically netty has an event cycle, so whenever you make a call it gets serialized and the request gets pushed down to the o/s level, and it uses epoll and waits for an event to send back to netty.
When the operation system generates an event that netty subscribed to, netty then has an event loop that gets triggered.
Now the interested part here is, the event that gets triggered has to be parsed, and the client code (or custom code) has to figure out who actually this event is for.
So for example, if this was for a chat application, when a message is sent, it is up to the client code to figure out to send this message via ajax to the correct user.
Is this, at a high level, a correct overview of how netty works?
BTW, when netty listens for events sent via epoll, is this event loop single threaded or does it work from a pool of threads?
Sounds correct to me.
There are more than one event loop thread in Netty, but it does not mean a single Channel's event is handled by multiple event loop threads. Netty picks one thread and assigns it to a Channel. Once assigned, all events related with the Channel is handled by the picked thread.
It does not also necessarily mean that an event loop thread handles only one Channel. An event loop thread can handle multiple Channels.