Skip to content

Commit 29ce108

Browse files
committed
add and update doc-comments
1 parent c3721f1 commit 29ce108

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

Source/deferred/deferred.swift

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,13 @@ open class Deferred<Value>
250250
return resolve(Result<Value, Error>(error: error))
251251
}
252252

253-
fileprivate func enqueue(source: AnyObject)
253+
/// Keep a strong reference to `source` until this `Deferred` has been resolved.
254+
///
255+
/// The implication here is that `source` is needed as an input to `self`.
256+
///
257+
/// - parameter source: a reference to keep alive until this `Deferred` is resolved.
258+
259+
fileprivate func retainSource(_ source: AnyObject)
254260
{
255261
var state = CAtomicsLoad(deferredState, .acquire)
256262
if !state.isResolved
@@ -470,7 +476,7 @@ public struct Resolver<Value>
470476
self.deferred = deferred
471477
}
472478

473-
/// Set the value of our `Deferred` and dispatch all notifications for execution.
479+
/// Resolve the underlying `Deferred` and execute all of its notifications.
474480
///
475481
/// Note that a `Deferred` can only be resolved once.
476482
/// On subsequent calls, `resolve` will fail and return `false`.
@@ -485,7 +491,7 @@ public struct Resolver<Value>
485491
return deferred?.resolve(result) ?? false
486492
}
487493

488-
/// Set the value of our `Deferred` and dispatch all notifications for execution.
494+
/// Resolve the underlying `Deferred` with a value, and execute all of its notifications.
489495
///
490496
/// Note that a `Deferred` can only be resolved once.
491497
/// On subsequent calls, `resolve` will fail and return `false`.
@@ -500,7 +506,7 @@ public struct Resolver<Value>
500506
return resolve(Result<Value, Error>(value: value))
501507
}
502508

503-
/// Set our `Deferred` to an error and dispatch all notifications for execution.
509+
/// Resolve the underlying `Deferred` with an error, and execute all of its notifications.
504510
///
505511
/// Note that a `Deferred` can only be resolved once.
506512
/// On subsequent calls, `resolve` will fail and return `false`.
@@ -515,7 +521,7 @@ public struct Resolver<Value>
515521
return resolve(Result<Value, Error>(error: error))
516522
}
517523

518-
/// Attempt to cancel the current operation, and report on whether cancellation happened successfully.
524+
/// Attempt to cancel the underlying `Deferred`, and report on whether cancellation happened successfully.
519525
///
520526
/// A successful cancellation will result in a `Deferred` equivalent to as if it had been initialized as follows:
521527
/// ```
@@ -531,7 +537,7 @@ public struct Resolver<Value>
531537
return cancel(DeferredError.canceled(reason))
532538
}
533539

534-
/// Attempt to cancel the `Deferred` represented by this `Resolver`
540+
/// Attempt to cancel the underlying `Deferred`, and report on whether cancellation happened successfully.
535541
///
536542
/// - parameter error: a `DeferredError` detailing the reason for the attempted cancellation.
537543
/// - returns: whether the cancellation was performed successfully.
@@ -542,7 +548,7 @@ public struct Resolver<Value>
542548
return resolve(Result<Value, Error>(error: error))
543549
}
544550

545-
/// Change the state of our `Deferred` from `.waiting` to `.executing`
551+
/// Change the state of the underlying `Deferred` from `.waiting` to `.executing`
546552

547553
public func beginExecution()
548554
{
@@ -568,9 +574,15 @@ public struct Resolver<Value>
568574
deferred?.notify(handler: { _ in handler() })
569575
}
570576

571-
public func retainSource(_ object: AnyObject)
577+
/// Keep a strong reference to `source` until this `Deferred` has been resolved.
578+
///
579+
/// The implication here is that `source` is needed as an input to `self`.
580+
///
581+
/// - parameter source: a reference to keep alive until this `Deferred` is resolved.
582+
583+
public func retainSource(_ source: AnyObject)
572584
{
573-
deferred?.enqueue(source: object)
585+
deferred?.retainSource(source)
574586
}
575587
}
576588

@@ -599,12 +611,20 @@ open class TBD<Value>: Deferred<Value>
599611
task(Resolver(self))
600612
}
601613

614+
/// Obtain an unresolved `Deferred` with a paired `Resolver`
615+
///
616+
/// - parameter queue: the `DispatchQueue` on which the notifications will be executed
617+
602618
public static func CreatePair(queue: DispatchQueue) -> (Resolver<Value>, Deferred<Value>)
603619
{
604620
let d = Deferred<Value>(queue: queue)
605621
return (Resolver(d), d)
606622
}
607623

624+
/// Obtain an unresolved `Deferred` with a paired `Resolver`
625+
///
626+
/// - parameter qos: the QoS at which the notifications should be performed; defaults to the current QoS class.
627+
608628
public static func CreatePair(qos: DispatchQoS = .current) -> (Resolver<Value>, Deferred<Value>)
609629
{
610630
let queue = DispatchQueue(label: "tbd", qos: qos)

0 commit comments

Comments
 (0)