observer-pattern

Observable not reacting to blocking collection changed on different thread

半世苍凉 提交于 2019-12-11 09:16:43
问题 I have the following code: class Program { static void Main(string[] args) { var watcher = new SNotifier(DumpToConsole); watcher.StartQueue(); Console.ReadLine(); } private static void DumpToConsole(IList<Timestamped<int>> currentCol) { Console.WriteLine("buffer time elapsed, current collection contents is: {0} items.", currentCol.Count); Console.WriteLine("holder has: {0}", currentCol.Count); } } the SNotifier: public class SNotifier { private BlockingCollection<int> _holderQueue; private

How to make ViewController observe any changes to ViewModel variables (Variable<..>) with RxSwift?

喜欢而已 提交于 2019-12-11 08:14:47
问题 How can I observe changes to Variable<...> value ( RxSwift Variable ) inside the ViewModel class from the ViewController ? So in case the value of any of my Variable<..> that I have in the ViewModel changes within the things happening in the ViewModel then the ViewController will be noticed "Hey! One or more Variable<..> in the ViewModel changed! Ask the ViewModel for the data you need to update the UI and update the UI!" And then the ViewController call a method updateUI() inside the

Adding an observer to an NSString

假如想象 提交于 2019-12-11 07:07:58
问题 In my application delegate I have an NSString which can be modified by a class. What I want to do is to have another class observe this NSString and to react whenever this NSString is changed. Does anybody know how I can do this? 回答1: On the "other class" you must do something like: [MyAppDelegate addObserver:self forKeyPath:@"VARIABLE_NAME" options:NSKeyValueObservingOptionNew context:nil]; and implement - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:

Rx.js, handling Chrome Extension webrequest API callback functions

99封情书 提交于 2019-12-11 06:01:25
问题 I'm trying to use Rx.js to handle the flow of Chrome extension webrequest API. Each webrequest addListener() call takes a mandatory callback function as the first parameter. This sends request objects to the function. However, the callback can return a webRequest.BlockingResponse that determines the further life cycle of the request. I'm struggling to handle the blocking response as part of the observable. This code works well for examining all image requests, for example

How to get payment method in an observer in Magento?

丶灬走出姿态 提交于 2019-12-11 05:58:36
问题 I have an observer that handles the event: sales_payment_invoice_pay (or something like that). What I'm trying to do is to send an invoice if the payment method is PayPal. Everything is ok in version 1.4~ by doing $observer->getEvent()->getOrder()->getPayment->getMethodInstance(). In version 1.5+ however I can't seem to find any solutions. I also tried with getData() but without any results. Any help is appreciated. thanks Calling me super desperate for an answer would be an understatement.

How do I implement observer pattern on PHP + Javascript/jQuery?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 04:42:30
问题 Just like in SO, where one is answering a question, if somebody has answered said question, a notification will appear (via AJAX?). My only way of somewhat replicating this is by including a timeout on my script that fetches if there is an update every n seconds. Is there a way to do this using observer pattern on PHP + Javascript (w/ jQuery)? 回答1: you have to look at the ReverseAJAX or COMET methodologies. As per wikipedia Reverse Ajax refers to an Ajax design pattern that uses long-lived

EventSource with Map<Class<? extends Event>, List<EventListener<? extends Event>> without unchecked call

馋奶兔 提交于 2019-12-11 03:05:06
问题 I need to implement Observer pattern with List of listeners per Event class. I have: empty interface Event public interface Event {} interface for Listeners: public interface EventListener<T extends Event> { void handle(T event); Class<T> getEventClass();} and event source: public class EventSource { private final Map<Class<? extends Event>, List<EventListener<? extends Event>>> listeners = new HashMap<>(); public <T> void subscribe(EventListener<? extends Event> listener) { Class<? extends

How to use a typedef function pointer to register a callback

倖福魔咒の 提交于 2019-12-11 02:39:10
问题 I'm trying to implement an observer pattern (of sorts) with C++ and I want to use function pointer to do so, but I keep getting an error when trying to cast a function pointer from class B to a typedef function pointer: #include <map> typedef int (*OutputEvent)(const char*, const char*, int); class A { private: int nextListenerId; std::map<int, OutputEvent> listenerMap; public: A(){ nextListenerId = 0;} ~A(){} inline int RegisterListener(OutputEvent callback) { nextListenerId++; listenerMap

Observer pattern Or DataBinding

半城伤御伤魂 提交于 2019-12-11 02:29:02
问题 My question is, would you implement the Observer pattern, or use databinding to do the following: At the moment, i'm initializing a list of GuiDataObj. When an event is triggered, I look up the GuiDataObjById and then modify the object, which is databound to a GuiElement; which updates the GUI. There are several GuiElements (at the moment are all of the same type, but this could change in the future), I want to be able to modify a class object, and have the GuiElement to auto-magically update

Android : Notified when all Async calls are completed

。_饼干妹妹 提交于 2019-12-11 01:38:16
问题 I am stuck in one implementation. I am developing an Android application, into which I integrated 3rd party SDK (library) and calling its APIs. Function calling of SDK is actually Async calls (WebAPI calls called by the library) which gives a response (success or failure). Now, I am trying to explain the situation by code. for (................) { AsyncAPICall (SuccessListener { onSuccess() { for (................) { AsyncAPICall (SuccessListener { onSuccess() { for (................) {