Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] DSF question

Hello, 

I am starting to use DSF and here is a common usage pattern I'm trying to impalement. 

Multiple clients request a single piece of data that is asynchronously retrieved only once.
When the data is finally retrieved it is made available to all clients. 

I was wandering if there is a helper class I should use instead of writing my own.  Is there better way to achieve this?

Here is the sketch of what I want to achieve - far from elegant or synchronized. 

Thanks in advance. 
Dobrin

Class ServiceX 
	Data data = null;
	Boolean dataRequested = false;
	ArrayList< DataRequestMonitor<Data >> initRMs = ArrayList< 				DataRequestMonitor<Data >>();

	Public Void SerivceX.getData( RequestMonitor rm){
		if( data != null) {
			rm.setData(data);	
			rm.done();
		}
		else {
			initRMs.add(rm); 
			if( !dataRequested) {
				dataRequested = true;
				requestData();
			}
		}
	}

	Void requstData( Context x) {
		Request the calls to the backend asyncronously.
      }

	When the data is finally available on the backend OnDone callback:
		data = ...;
		for(DataRequestMonitor rm : initRMs) {
			rm.setData(data);
			rm.done();	
		}




Back to the top