Overview
A helper class for opening containers.
This is a wrapper around openContainerById:callback: (TAGManager) method for callers that provides support for timeouts.
The following is a sample showing waiting up to 0.1 seconds for the container to be loaded before reverting to the default container:
NSTimeInterval timeout = 0.1; TagManager *tagManager = [TagManager instance]; TAGContainerFuture *future = [TAGContainerOpener openContainerWithId:@"GTM-XXXX" tagManager:tagManager openType:kTAGOpenTypePreferNonDefault timeout:&timeout]; TAGContainer *container = [future get];
If the caller wants to be asynchronously notified when the container is available but wants to manually specify the timeout to 0.5 seconds, then the caller should subclass TAGContainerOpenerNotifier, make the call to openContainerWithId:tagManager:openType:timeout:notifier: (TAGContainerOpener) with timeout set to 0.5, and add the implementation to containerAvailable: (TAGContainerOpenerNotifier-p) for handling the container available notification.
Static Public Member Functions | |
(id< TAGContainerFuture >) | + openContainerWithId:tagManager:openType:timeout: |
Waits up to timeout seconds for a container to be loaded (non default or fresh depending on the specified openType ) and returns a TAGContainerFuture . | |
(void) | + openContainerWithId:tagManager:openType:timeout:notifier: |
Waits up to timeout seconds for a container to be loaded (non default or fresh depending on the specified openType ) and calls a notifier when the container is available. | |
(NSTimeInterval) | + defaultTimeout |
Returns the default timeout for requesting the container. |
Member Function Documentation
+ (id<TAGContainerFuture>) openContainerWithId: | (NSString *) | containerId | |
tagManager: | (TAGManager *) | tagManager | |
openType: | (TAGOpenType) | openType | |
timeout: | (NSTimeInterval *) | timeout | |
Waits up to timeout
seconds for a container to be loaded (non default or fresh depending on the specified openType
) and returns a TAGContainerFuture
.
If the open type is kTAGOpenTypePreferNonDefault
, a non-default (saved or retrieved from network) container is loaded and the TAGContainerFuture
is unblocked as soon as one of the following happens:
- a saved container is loaded.
- if there is no saved container, a network container is loaded or a network error occurs.
- the timer expires.
If a network error occurs or the timer expires, get (TAGContainerFuture-p) may return a default container.
If the open type is kTAGOpenTypePreferFresh
, a fresh (saved or retrieved from network) container is loaded and the TAGContainerFuture is unblocked as soon as one of the following happens:
- a saved fresh container is loaded.
- if there is no saved container or saved container is stale, a network container is loaded or a network error occurs.
- the timer expires.
If a network error occurs or the timer expires, get (TAGContainerFuture-p) may contain defaults or a stale saved container.
If you call one of the openContainer methods a second time with a given containerId
, a TAGContainerFuture
will be returned whose get (TAGContainerFuture-p) will return the same container as the first call did.
- Parameters:
-
containerId The ID of the container to load. tagManager The TAGManager for getting the container. timeout The maximum number of seconds to wait to load the container from the saved store. If nil, defaultTimeout will be used. openType The choice of how to open the container.
- Returns:
- A TAGContainerFuture that will wait for up to
timeout
and return the container when it is available.
+ (void) openContainerWithId: | (NSString *) | containerId | |
tagManager: | (TAGManager *) | tagManager | |
openType: | (TAGOpenType) | openType | |
timeout: | (NSTimeInterval *) | timeout | |
notifier: | (id< TAGContainerOpenerNotifier >) | notifier | |
Waits up to timeout
seconds for a container to be loaded (non default or fresh depending on the specified openType
) and calls a notifier when the container is available.
If the open type is kTAGOpenTypePreferNonDefault
, a non-default (saved or retrieved from network) container is loaded and passed into the notifier. The notifier is called as soon as one of the following happens:
- a saved container is loaded.
- if there is no saved container, a network container is loaded or a network error occurs.
- the timer expires.
If a network error occurs or the timer expires, the container passed into the notifier is a default container.
If the open type is kTAGOpenTypePreferFresh
, a fresh (saved or retrieved from network) container is loaded and passed into the notifier. The notifier is called as soon as one of the following happens:
- a saved fresh container is loaded.
- if there is no saved container or saved container is stale, a network container is loaded or a network error occurs.
- the timer expires.
If a network error occurs or the timer expires, the container passed into the notifier may contain defaults or a stale saved container.
If you call one of the openContainer methods a second time with a given containerId
, the same container returned from the previous call will be passed into the notifier as soon as it's available.
- Parameters:
-
containerId The ID of the container to load. tagManager The TAGManager used for getting the container. openType The choice of how to open the container. timeout The maximum number of seconds to wait to load the container from the saved store. If nil, defaultTimeout will be used. notifier An optional notifier which will be called when the container is available. It will be called with the fresh container, if available and loaded before the timeout; otherwise it'll be called with a non-fresh container. Note that the notifier may be called from a different thread.
+ (NSTimeInterval) defaultTimeout |
Returns the default timeout for requesting the container.
- Returns:
- The default timeout in seconds.