|
|
@ -11,12 +11,14 @@ public extension AnyPromise {
|
|
|
|
* promise to self retain, until it completes to avoid the risk it's GC'd before completion.
|
|
|
|
* promise to self retain, until it completes to avoid the risk it's GC'd before completion.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@objc
|
|
|
|
@objc
|
|
|
|
func retainUntilComplete() {
|
|
|
|
@discardableResult
|
|
|
|
|
|
|
|
func retainUntilComplete() -> AnyPromise {
|
|
|
|
var retainCycle: AnyPromise? = self
|
|
|
|
var retainCycle: AnyPromise? = self
|
|
|
|
_ = self.ensure {
|
|
|
|
_ = self.ensure {
|
|
|
|
assert(retainCycle != nil)
|
|
|
|
assert(retainCycle != nil)
|
|
|
|
retainCycle = nil
|
|
|
|
retainCycle = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -25,12 +27,14 @@ public extension PMKFinalizer {
|
|
|
|
* Sometimes there isn't a straight forward candidate to retain a promise, in that case we tell the
|
|
|
|
* Sometimes there isn't a straight forward candidate to retain a promise, in that case we tell the
|
|
|
|
* promise to self retain, until it completes to avoid the risk it's GC'd before completion.
|
|
|
|
* promise to self retain, until it completes to avoid the risk it's GC'd before completion.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
func retainUntilComplete() {
|
|
|
|
@discardableResult
|
|
|
|
|
|
|
|
func retainUntilComplete() -> PMKFinalizer {
|
|
|
|
var retainCycle: PMKFinalizer? = self
|
|
|
|
var retainCycle: PMKFinalizer? = self
|
|
|
|
_ = self.finally {
|
|
|
|
_ = self.finally {
|
|
|
|
assert(retainCycle != nil)
|
|
|
|
assert(retainCycle != nil)
|
|
|
|
retainCycle = nil
|
|
|
|
retainCycle = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -39,12 +43,14 @@ public extension Promise {
|
|
|
|
* Sometimes there isn't a straight forward candidate to retain a promise, in that case we tell the
|
|
|
|
* Sometimes there isn't a straight forward candidate to retain a promise, in that case we tell the
|
|
|
|
* promise to self retain, until it completes to avoid the risk it's GC'd before completion.
|
|
|
|
* promise to self retain, until it completes to avoid the risk it's GC'd before completion.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
func retainUntilComplete() {
|
|
|
|
@discardableResult
|
|
|
|
|
|
|
|
func retainUntilComplete() -> Promise<T> {
|
|
|
|
var retainCycle: Promise<T>? = self
|
|
|
|
var retainCycle: Promise<T>? = self
|
|
|
|
_ = self.ensure {
|
|
|
|
_ = self.ensure {
|
|
|
|
assert(retainCycle != nil)
|
|
|
|
assert(retainCycle != nil)
|
|
|
|
retainCycle = nil
|
|
|
|
retainCycle = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -53,11 +59,13 @@ public extension Guarantee {
|
|
|
|
* Sometimes there isn't a straight forward candidate to retain a promise, in that case we tell the
|
|
|
|
* Sometimes there isn't a straight forward candidate to retain a promise, in that case we tell the
|
|
|
|
* promise to self retain, until it completes to avoid the risk it's GC'd before completion.
|
|
|
|
* promise to self retain, until it completes to avoid the risk it's GC'd before completion.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
func retainUntilComplete() {
|
|
|
|
@discardableResult
|
|
|
|
|
|
|
|
func retainUntilComplete() -> Guarantee<T> {
|
|
|
|
var retainCycle: Guarantee<T>? = self
|
|
|
|
var retainCycle: Guarantee<T>? = self
|
|
|
|
_ = self.done { _ in
|
|
|
|
_ = self.done { _ in
|
|
|
|
assert(retainCycle != nil)
|
|
|
|
assert(retainCycle != nil)
|
|
|
|
retainCycle = nil
|
|
|
|
retainCycle = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|