observer-pattern

Observers in Rails Engines

£可爱£侵袭症+ 提交于 2019-12-10 22:59:28
问题 I'm trying to create an observer in my Rails engine that will observe a model in my main application. My observer (in app/models/my_engine/my_observer.rb) is, module MyEngine class MyObserver < ActiveRecord::Observer observe AppModel def after_create # code to run when callback is observed end end end In order to register the observer, I've modified my engine (in lib/my_engine/engine.rb) to be, module MyEngine class Engine < ::Rails::Engine isolate_namespace MyEngine config.active_record

Android LiveData: Not receiving all notifications

这一生的挚爱 提交于 2019-12-10 18:29:46
问题 I'm experimenting with Android's LiveData. I just tried to push a lot of notifications to an observer that observes a LiveData object. I let a thread run in background and in a while-loop i constantly push random values via LiveData's postValue-method. The number of received notifications (number of onChanged()-callbacks) in the observer which observes the livedata is much less then the number of calls of postValue in the background thread. Can somebody explain what's the reason for this?

Observer pattern - when to

跟風遠走 提交于 2019-12-10 14:58:49
问题 We have been arguing back and forth at my work place about the use of the Observer pattern for one of the problems. I somehow smell "overuse" but am open to ideas. So the requirement is We have a hierarchy of objects -> an order and multiple line items in the order. When the order is cancelled, all the line items need to cancelled. To do this, we have created a OrderCancel class which is the Subject in the Observer pattern idiom and LineItemCancel class which is the Observer. We also have a

Weld - Asynchronous event observers

跟風遠走 提交于 2019-12-10 14:00:29
问题 I am using Weld to observe events. I thought there was a way to specify if the observer was asynchronous or not, but I am not finding that annotation or documentation. Can observers be asynchronous, if so, what do I need to do to make that happen? 回答1: There is an open request for this: CDI-31: Asynchronous events. Depending on your requirements, you can, as indicated in your comment, set a different transactional observer: If you use AFTER_COMPLETION or AFTER_SUCCESS, it should seem to your

Observer pattern with threads

穿精又带淫゛_ 提交于 2019-12-10 13:02:35
问题 I want to run several threads and join them at the end of my main method, so I can know when they have finished and process some info. I don't want to put my threads in an array and do a join() one by one as join is a blocking method and I stay would waiting in the main thread for some threads still running, while other threads may have already finished, without having a possibility of knowing. I have thought on the possibility of implementing an observer pattern for my threads: An interface

Continue using subscription after exception

孤街醉人 提交于 2019-12-10 11:41:07
问题 I was trying out a "type-to-search" Reactive-Extensions sample which takes a string from a textbox (WPF app if it matters) and does a potentially-lengthy server-side search (simulated in my case with a Thread.Sleep) and displays the result(s) in a listbox. The key features of this particular "module" would be : async search; UI is not frozen while searching throttled; typing fast would not generate a server-side search for each keystroke distinct searching; after searching for "asd" and

Registering weak_ptr observer in constructor

别来无恙 提交于 2019-12-10 10:56:19
问题 I'm trying to rewrite our Observer / Observable implementation to use std::shared_ptr/std::weak_ptr to get rid of some nasty race conditions currently present in the code. Typically, the observers registers themselves when some condition is met or when they are constructing child objects like so: // Used to be raw 'this' now child instead derives a weak_ptr and stores it child->addObserver(shared_from_this()) And unregisters themselves in destructor like so: child->removeObserver(this); //

Correct way to merge observable sequences for events fired from multiple instances

倖福魔咒の 提交于 2019-12-10 10:31:47
问题 Say I have a factory method that churns out instances of type T, and I want an Rx observable sequence for events fired from all my instances originating out of the factory method. Is using Merge() as I have done below the correct and optimal way to achieve this? The other way I did this was to use a static event and make the observable sequence out of that, however I generally don't like using static events and am curious what any Rx experts think would be optimal in this situation? public T

Am I allowed to observe a ViewModel, if I clean up the back references?

牧云@^-^@ 提交于 2019-12-10 10:19:26
问题 The suggested way to implement ViewModel is to expose the changing data by using LiveData objects to activities, fragments and views. There are cases, when LiveData is not an ideal answer or no answer at all. The natural alternative would be, to apply the observer pattern to the ViewModel , make it an observable. When registering observers to the ViewModel , the ViewModel will hold callback references to notify the observers. The documentation says, a ViewModel must not hold references to

How to set an Observer to Update Navigation Drawer after onActivityResult method's received an Intent result

╄→гoц情女王★ 提交于 2019-12-10 06:59:07
问题 In my app I want to update the Navigation Drawer with the username's nickname and email after he's logged in. From my MainActivity I am starting a LoginActivity with the startActivityForResult(intent, PICK_ACCOUNT_REQUEST); method to get the users registered or logged in. After the LoginActivity returns the Intent data result (his NAME and EMAIL ) back to MainActivity , the method onActivityResult() is called and there I try to update the class' global variables NAME and EMAIL with the newly