Is there a way to subscribe to an event and handle it asynchronously using the event+=EventHandler
syntax or is there any workaround to achieve it
The event/delegate system calls each of the subscribed event handles synchronously on the thread the fires the event. To make the event handler processing be done asynchrounously, it has to be part of the function that you subscribe to the event.
Related
In MDN it says "The suspend event is fired when media data loading has been suspended." But what does this actually mean? What are some examples for this event. I'm especially interested in the context of an audio stream.
docs: https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/suspend_event
The suspend event occurs when the browser is intentionally not getting media data. This event is triggered when the loading of the media is suspended, suspended means when the download of a media has been completed, or it has been paused for some other reasons
I want to cancel a stream, and found that a Stream cannot be canceled, but a StreamSubsciption can be canceled. Stream object has a listen() method which
Adds a subscription to this stream.
What actually is a subscription? and how do I use it with StreamBuilder?
From the docs:
A subscription on events from a Stream.
When you listen on a Stream using Stream.listen, a StreamSubscription object is returned.
The subscription provides events to the listener, and holds the callbacks used to handle the events. The subscription can also be used to unsubscribe from the events, or to temporarily pause the events from the stream.
From what I understand, I think I can use the event and use it to rebuild my widgets. Is it the right way to do it? or is there is a more correct way to do it?
If you are using StreamBuilder, stream subscription and stream cancelling is managed by the framework. The builder method will be called when new snapshot is available, and when the widget is destroyed, stream subscription is cancelled.
As you wrote, you can create your own StreamSubscription with listen() method, and in this case you have to cancel this subscription when you no longer need it, for example in an overridden dispose method. To do so keep track of subscription in a variable or a member, assuming you have a stream in stream variable and MyType is the class which is returned by stream:
StreamSubscription<MyType> myStreamSubscription = stream.listen((value) {
// add code here
});
Then you can use this to manage the stream:
myStreamSubscription.pause();
myStreamSubscription.resume();
myStreamSubscription.cancel();
I am new to flutter and the famous flutter_bloc library. I have created a chat system based on the BLoC pattern :
A widget fires an event to chatBloc
The chatBloc catches the event, process it and call chatRepository
ChatRepository adds the message as a draft in its messageList variable and then sends the message to the API
ChatRepository receives the message from the API when it is done and replaces the draft within its messageList variable
ChatBloc yields its final state and the page rebuilds
Everything works fine as long as no more than one message is processed at a time.
If my button widget fires two quick events, they will overlap and so the second event will fire while the first event is still in progress. By the time when the second event starts, the first message is still a draft, so when message 2 completes and chatRepository updates its messageList, it will treat message 1 as a draft even if it has been validated.
At this point I'm asking myself if I made a mistake or if I'm trying to do it the wrong way.
Would it be better to create a queue and process messages in the background one by one ?
Thank you for your help !
How can I get the following events?
Initiate Call event
Call received event
Call missed event
Call end event
You can use onConnectionStateChanged() callback for most of these functions.
You can read about these functions over here:
https://docs.agora.io/en/Video/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_i_rtc_channel_event_handler.html#a6dfbfe241ac004b792a499c29033ddff
I'm trying to stop postback from happening if a certain condition is met in the XMLHttpRequest's callback function. I've used return false from within the function, but the postback happens anyway. Is there a way to stop it in such a case?
When the callback function is called the postback has already happened so it will be to late to try to stop it.
The callback is called by the XMLHttpRequest once it receives the result back from the server.