Perl and IRC: Periodically send a message to a channel - perl

I'm making a Perl IRC bot and I want to send a message periodically to a channel. I'm using POE::Component::IRC, but as far as I can see, there is no method or event handling this.
Is there a way to accomplish this?

You can use POE::Kernel's delay routine to act like a one-time timer calling itself over and over.
Basically, you have an event handler named my_event. Within my_event, you send the PRIVMSG to the channel. You then call this same event handler my_event using the delay routine inherited through POE.
See: POE: Cookbook - Recurring Alarms

Related

How to receive data from an api without any user interaction

I'm trying to receive some data from an API call and do some task based on the received data.
Let's say I have my flutter app opened and in that opened state without any click or any interaction I get some data or do any function when I send something through the API.
I used Firebase FCM to do such task - When I send something through the API the firebase notification captures that data and doing the tasks I want on the flutter app.
But I want to do without Firebase. How can I do that. Any solution/suggestions would be great. Thanks!
At first, let's put Flutter aside. Your problem is to pull data from API and do a specific task OR your API should notify the app through API.
For the first problem, a simple data polling should work: when the app is opened, you just start some kind of timer and periodically pull data from the API and do something. However, this method is not perfect, it drains the battery and in general, there are better ways to achieve the same thing, for instance using sockets or push notifications (as some of the answers already state that).
For your second problem - "or do any function when I send something through the API" - you need some kind of mechanism to notify your app for it to react and process the data. This one could be handled using the same mechanism as for the first problem.
So, probably you need to use some kind of push notification service (for instance OneSignal or Pusher, or any other similar service) or web sockets (https://flutter.dev/docs/cookbook/networking/web-sockets).
Your question is little bit unclear. Whatever if you want to do some network call even without any interaction by user you can call network in your onInit method. This method runs at the very beginning for individual screen. Then do your task based on the response
You need stream API for this,look into socket programming
You can use webs socket or pusher for this. When web socket is connected with your server that time you received some data and you can do your task.

Is it possible to get a response from event fired through Akka Event Stream (scala)?

In are app, we are quite heavily using Akka Event Stream to handle logic that is not related to the main business flow. Things like: send emails, sync records, etc... All of these events are currently fired and forgotten.
system.eventStream.publish(<event>)
And they are handled by listeners, asynchronously, in most cases.
However, I am now investigating an option of extending class functionality through events system and that, sometimes, requires a return value from an event?
Is it even possible to get some result back from an event? I could not find anything specific in this regard.
Thanks,
It's a feature of event based systems: you know who triggered the event, you don't know who will handle it, nor when (can be asynchronous).
So, the most idiomatic solution, if your listener should generate an answer, is to do it in an asynchronous way. And as such, the listener should send an event with it's answer.
Another way to do it is to bypass the event bus and register you handlers as listeners of your event source (you should handle your self the registe/unregister functions through akka messages and a simple list). And when your event source triggers the listeners, it can do it using the ask pattern.

what kind of GCD queue or timer should I use for a debounce function

Just learning GCD and wanted some guidance. I'd like to set up a debounce function so that a logoff notification for users I'm following doesn't appear for 5 minutes in case that user log right back in. In this case I'd like to have a delayed logoff UI notification get added to a timeout queue to execute 5 minutes from now - unless that user logs back in in which case I would cancel that specific notification in the queue. (note user in these examples is not me - the currently logged in active user).
Which type of GCD queue should I use?
Main
QOS_CLASS_USER_INTERACTIVE
QOS_CLASS_USER_INITIATED,
QOS_CLASS_UTILITY,QOS_CLASS_BACKGROUND
example
How can I debounce a method call?
I also found an example using a timer - is that different or same as a GCD call under the covers?
Search as you type Swift
GCD is best at fire-and-forget tasks where you set up some work to be done and don't make any adjustments after that.
A simple version of what you want would be to use a NSTimer. If the user logs in, you invalidate the timer. If the timer survives and fires, you send your notification.
If, for some reason, you need to involve extra threading in this, look at NSOperationQueue instead of GCD. That lets you examine the queue and apply cancellation logic.

GWT: Is Timer the only way to keep my app up-to-date with the server?

I just got asked to reduce the traffic made by my GWT app. There is one method that checks for status.
This method is an asynchronous call wrapped in a Timer. I know web apps are stateless and all that, but I do wonder if there is some other way to do this, or if everyone has a Timer wrapped around a call when they need this kind of behaviour.
You can check out gwteventservice. It claims to have a way to push server events and notify the client.
I have a feeling they might be implemented as long running (hanging) client to server RPC calls which time out after an interval (say 20sec), and then are re-made. The server returns the callback if an event happens in the meanwhile.
I haven't used it personally but know of people using it to push events to the client. Have a look at the docs . If my assumption is correct, the idea is to send an RPC call to the server which does not return (hangs). If an event happens on the server, the server responds and that RPC call returns with the event. If there is no event, the call will time out in 20 seconds. Then a new call is made to the server which hangs in the same way until there is an event.
What this achieves is that it reduces the number of calls to the server to either one for each event (if there is one), or a call once every 20 seconds (if there isn't one). It looks like the 20 sec interval can be configured.
I imagine that if there is no event the amount of data sent back will be minimal - it might be possible to cancel the callback entirely, or have it fail without data transfer, but I don't really know.
Here is another resource on ServerPush - which is likely what's implemented by gwteventservice.
Running on Google app engine you could use they Channel technology
http://code.google.com/intl/en-US/appengine/docs/java/channel/overview.html
If you need the client to get the status from the server, then you pretty much have to make a call to the server to get it's status.
You could look at reducing the size of some of your messages
You could wind back the timer so the status call goes out less often
You could "optimise" so that the timer gets reset when some other client/server IO happens (i.e. if the server replies you know it is ok, so you don't need to send the next status request).

What's Android Equivalent of iOS's Post Notification and Delegate function?

I find the Post notification and delegate function are very useful in iOS. Once I finish a task I can notify another piece of code to do something. I am sending out notices for others to do the work.
Post Notification is when you sending notice right away, whereas delegate sometime down the line it will send a notice.
In Android I know there's event Listener, but that's only passive listening. What about me actively sending notices? Does Android have that equivalent?
Handler which can be fired right away or with postDelay() you can fire them later
You could either use a Handler to get notified from a running Thread or the AsyncTask which does run some code and after it's finished it notifies the UI Thread.
You are probably looking for a way to thread your application? Where there are other "worker" threads that do long computations (or do buffered IO stuff). The way you would do this is by creating an AsyncTask. Within an AsyncTask, there is a "doInBackground" method that seems to be what "delegate" is in your question. "onPostExecute" will handle whatever's returned in "doInBackground". More in the AsyncTask documentation.
Another option is to simply use a Handler and use postDelay() for later executions: