2014-05-06 19:41:08 +02:00
|
|
|
#import <Foundation/Foundation.h>
|
2014-08-20 14:08:32 +02:00
|
|
|
#import "CollapsingFutures.h"
|
2014-05-06 19:41:08 +02:00
|
|
|
#import "Queue.h"
|
|
|
|
|
|
|
|
typedef void (^LatestValueCallback)(id latestValue);
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* An ObservableValue represents an asynchronous stream of values, such as 'latest state of toggle' or 'latest sensor reading'.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
@interface ObservableValue : NSObject {
|
|
|
|
@protected NSMutableSet* callbacks;
|
|
|
|
@private Queue* queuedActionsToRun;
|
|
|
|
@private bool isRunningActions;
|
|
|
|
@protected bool sealed;
|
|
|
|
}
|
|
|
|
|
|
|
|
@property (readonly,atomic) id currentValue;
|
|
|
|
|
|
|
|
-(void) watchLatestValueOnArbitraryThread:(LatestValueCallback)callback
|
2014-08-20 14:08:32 +02:00
|
|
|
untilCancelled:(TOCCancelToken*)untilCancelledToken;
|
2014-05-06 19:41:08 +02:00
|
|
|
|
|
|
|
-(void) watchLatestValue:(LatestValueCallback)callback
|
|
|
|
onThread:(NSThread*)thread
|
2014-08-20 14:08:32 +02:00
|
|
|
untilCancelled:(TOCCancelToken*)untilCancelledToken;
|
2014-05-06 19:41:08 +02:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface ObservableValueController : ObservableValue
|
|
|
|
|
|
|
|
+(ObservableValueController *)observableValueControllerWithInitialValue:(id)value;
|
|
|
|
-(void)updateValue:(id)value;
|
|
|
|
-(void)adjustValue:(id(^)(id))adjustment;
|
|
|
|
-(void)sealValue;
|
|
|
|
|
|
|
|
@end
|