-
Notifications
You must be signed in to change notification settings - Fork 1
TaskStore
The task store keeps track of all tasks passed into it. It stops duplicate tesks being called by canceling any already running tasks passed to it, until they are done and removed.
The store to hold references to the tasks being managed.
Declaration
Swift
private lazy var store = String: Any
---
<br>
### locked
Describes if the store is locked true or not false. This is set to false by default and is only locked when canceling all tasks.
**Declaration**
> <sub>**Swift**</sub>
> ```swift
private var locked = false
Add a rquest to the store with a url string (normally absolute is sugested) to use as the key to store the task under in the store.
Declaration
Swift
public func add(_ task: URLSessionTask, urlString: String) -> Bool
**Parameters**
<table>
<tr><td> `task` </td><td> The task to store and manage. </td></tr>
<tr><td> `urlString` </td><td> The url string to use as the key. </td></tr>
<table>
**Return Value**
true if added or false if not (either from lock or already existing in the store).
---
<br>
### add(_:urlString:)
Add a rquest to the store with a url string (normally absolute is sugested) to use as the key to store the operation under in the store.
**Declaration**
> <sub>**Swift**</sub>
> ```swift
public func add(_ operation: Operation, urlString: String) -> Bool
Parameters
| `operation` | The operation to store and manage. |
| `urlString` | The url string to use as the key. |
Return Value
true if added or false if not (either from lock or already existing in the store).
Remove a task using a url string (normally absolute is sugested) as the key.
Declaration
Swift
public func remove(taskWithURL urlString: String)
**Parameters**
<table>
<tr><td> `urlString` </td><td> The url string to use as the key of the task to remove. </td></tr>
<table>
---
<br>
### cancel(_:)
Internal function for canceling an item in the store, when it’s unknown if it’s a task or operation.
**Declaration**
> <sub>**Swift**</sub>
> ```swift
private func cancel(_ item: Any)
Parameters
| `item` | The item (task/operation) to cancel. |
Cancel all tasks currently in the store. This function will lock the store as it cancels all it’s content, stopping any new tasks to be added.
Declaration
Swift
public func cancelAllTasks()
---
<br>
### contains(taskWithURL:)
Checks to see if there is a rquest in the store that matches the passed in url string.
**Declaration**
> <sub>**Swift**</sub>
> ```swift
public func contains(taskWithURL urlString: String) -> Bool
Parameters
| `urlString` | The url string to check for. |
Return Value
If a matching task is found then true is returned, otherwise false is returned.