 
 class PromiseKTests: XCTestCase {
     func testMap() {
-        let expectation = self.expectation(description: "")
-
-        _ = asyncGet(3).map {
-            XCTAssertEqual($0, 3)
-            return $0 * $0
-        }.map { (value: Int) in
-            XCTAssertEqual(value, 9)
-            expectation.fulfill()
-        }
-        
-        waitForExpectations(timeout: 3.0, handler: nil)
+        let squared = asyncGet(3).map {
+            $0 * $0
+        }
+        
+        XCTAssertEqual(squared.sync(), 9)
     }
     
     func testFlatMap() {
         do {
-            let expectation = self.expectation(description: "")
-            
-            _ = asyncGet(3).flatMap { value -> Promise<()> in
-                XCTAssertEqual(value, 3)
-                expectation.fulfill()
-                return Promise<()>()
-            }
-            
-            waitForExpectations(timeout: 3.0, handler: nil)
-        }
-        
-        do {
-            let expectation = self.expectation(description: "")
-            
-            _ = asyncGet(3).flatMap { (value: Int) in
-                XCTAssertEqual(value, 3)
-                return asyncGet(value * value)
-            }.flatMap { (value: Int) -> Promise<()> in
-                XCTAssertEqual(value, 9)
-                expectation.fulfill()
-                return Promise<()>()
-            }
-            
-            waitForExpectations(timeout: 3.0, handler: nil)
+            let a = asyncGet(2)
+            let b = asyncGet(3)
+            let sum = a.flatMap { a in
+                b.map { b in
+                    a + b
+                }
+            }
+            
+            XCTAssertEqual(sum.sync(), 5)
+        }
+        
+        do {
+            let sum = asyncGet(2).flatMap { a in
+                asyncGet(3).map { b in
+                    a + b
+                }
+            }
+            
+            XCTAssertEqual(sum.sync(), 5)
         }
     }
     

            let expectation = self.expectation(description: "\(i)")
            
            let promise = Promise<Int> { resolve in
                queue1.asyncAfter(deadline: DispatchTime.now() + Double(Int64(0.01 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)) {
                    resolve(Promise(2))
                }
            }
            
            queue2.asyncAfter(deadline: DispatchTime.now() + Double(Int64(0.01 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)) {
                let _: Promise<Int> = promise.flatMap {
                    expectation.fulfill()
                    return Promise($0 * $0)

    return asyncGetOrFail(value, arc4random() % 2 == 0)
}

struct FooError: Error {
    var value: Int
}
