Skip to content

Commit

Permalink
Merge pull request #1002 from mxcl/fixes-1001
Browse files Browse the repository at this point in the history
Fixes 1001
  • Loading branch information
repo-ranger[bot] authored Jan 28, 2019
2 parents cc89b4f + 6264f6f commit d513112
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ branches:
stages:
- name: pretest
- name: lint
if: NOT branch =~ ^\d+\.\d+\.\d+$
- name: compile
if: type != push OR branch =~ /^\d+\.\d+\.\d+$/
- name: test
Expand Down Expand Up @@ -194,5 +195,5 @@ jobs:
# BUT `--verbose` generates so much output that Travis kills our script due to *too much* output!
# --allow-warnings because Bolts generates warnings and CocoaPods fails you even if your deps emit warnings
os: osx
osx_image: xcode10.1
osx_image: xcode10.0 # 10.0 or CocoaPods barfs
language: objective-c
2 changes: 1 addition & 1 deletion Sources/Box.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class SealedBox<T>: Box<T> {
}
}

final class EmptyBox<T>: Box<T> {
class EmptyBox<T>: Box<T> {
private var sealant = Sealant<T>.pending(.init())
private let barrier = DispatchQueue(label: "org.promisekit.barrier", attributes: .concurrent)

Expand Down
26 changes: 14 additions & 12 deletions Sources/Guarantee.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Dispatch
- See: `Thenable`
*/
public final class Guarantee<T>: Thenable {
let box: Box<T>
let box: PromiseKit.Box<T>

fileprivate init(box: SealedBox<T>) {
self.box = box
Expand All @@ -19,7 +19,7 @@ public final class Guarantee<T>: Thenable {

/// Returns a pending `Guarantee` that can be resolved with the provided closure’s parameter.
public init(resolver body: (@escaping(T) -> Void) -> Void) {
box = EmptyBox()
box = Box()
body(box.seal)
}

Expand Down Expand Up @@ -54,19 +54,21 @@ public final class Guarantee<T>: Thenable {
}
}

init(_: PMKUnambiguousInitializer) {
box = EmptyBox()
}

deinit {
switch box.inspect() {
case .pending:
PromiseKit.conf.logHandler (.pendingGuaranteeDeallocated)
case .resolved:
break
final private class Box<T>: EmptyBox<T> {
deinit {
switch inspect() {
case .pending:
PromiseKit.conf.logHandler(.pendingGuaranteeDeallocated)
case .resolved:
break
}
}
}

init(_: PMKUnambiguousInitializer) {
box = Box()
}

/// Returns a tuple of a pending `Guarantee` and a function that resolves it.
public class func pending() -> (guarantee: Guarantee<T>, resolve: (T) -> Void) {
return { ($0, $0.box.seal) }(Guarantee<T>(.pending))
Expand Down

0 comments on commit d513112

Please sign in to comment.