             }
         }
     }
-}
-
-extension SDTask {
-    
-    /// Return `true` iff task is completed.
-    public final var completed: Bool {
-        return _lck.synchronized { _result != nil }
-    }
-    
-    /// Result of task.
-    public final var result: Result {
-        if !completed {
-            dispatch_semaphore_wait(self.sem, DISPATCH_TIME_FOREVER)
-            defer { dispatch_semaphore_signal(self.sem) }
-        }
-        return self._result!
-    }
-}
-
-extension SDTask {
-    
-    /// Run `block` after `self` is completed.
-    public final func then<R>(block: (Result) -> R) -> SDTask<R> {
-        return self.then(queue, block)
-    }
-    
-    /// Run `block` after `self` is completed with specific queue.
-    public final func then<R>(queue: dispatch_queue_t, _ block: (Result) -> R) -> SDTask<R> {
+    
+    final func apply<R>(queue: dispatch_queue_t, _ suspend: ((R) -> Bool)?, _ block: (Result) -> R) -> SDTask<R> {
         var storage: Result!
-        let task = SDTask<R>(queue: queue, suspend: nil) { block(storage) }
+        let task = SDTask<R>(queue: queue, suspend: suspend) { block(storage) }
         return _lck.synchronized {
             if _result == nil {
                 _notify.append {

    
    /// Suspend if `result` satisfies `predicate` with specific queue.
    public final func suspend(queue: dispatch_queue_t, _ predicate: (Result) -> Bool) -> SDTask<Result> {
        var storage: Result!
        let task = SDTask<Result>(queue: queue, suspend: predicate) { storage }
        return _lck.synchronized {
            if _result == nil {
                _notify.append {
                    storage = $0
                    task.signal()
                }
            } else {
                storage = _result
                task.signal()
            }
            return task
        }
    }
}



extension SDTask {
    
    /// Return `true` iff task is completed.
    public final var completed: Bool {
        return _lck.synchronized { _result != nil }
    }
    
    /// Result of task.
    public final var result: Result {
        if !completed {
            dispatch_semaphore_wait(self.sem, DISPATCH_TIME_FOREVER)
            defer { dispatch_semaphore_signal(self.sem) }
        }
        return self._result!
    }
}

extension SDTask {
    
    /// Run `block` after `self` is completed.
    public final func then<R>(block: (Result) -> R) -> SDTask<R> {
        return self.then(queue, block)
    }
    
    /// Run `block` after `self` is completed with specific queue.
    public final func then<R>(queue: dispatch_queue_t, _ block: (Result) -> R) -> SDTask<R> {
        return apply(queue, nil, block)
    }
}

extension SDTask {
    
    /// Suspend if `result` satisfies `predicate`.
    public final func suspend(predicate: (Result) -> Bool) -> SDTask<Result> {
        return self.suspend(queue, predicate)
