     /// Run `block` after `self` is completed with specific queue.
     public final func then<R>(queue: dispatch_queue_t, _ block: (Result) -> R) -> SDTask<R> {
         return _lck.synchronized {
-            if _result != nil {
-                return SDTask<R>(queue: queue) { block(self.result) }
-            }
-            let task = SDTask<R>(queue)
-            _notify.append { task.submit { block(self.result) } }
+            let task = SDTask<R>(queue: queue, suspend: { _ in false }) { block(self.result) }
+            if _result == nil {
+                _notify.append(task)
+            } else {
+                task.signal()
+            }
             return task
         }
     }


// MARK: SDTask

public class SDTask<Result> {
    
    private let sem: dispatch_semaphore_t = dispatch_semaphore_create(0)
    private let group: dispatch_group_t = dispatch_group_create()
    private let queue: dispatch_queue_t
    
    private typealias NotifyType = () -> ()
    private var _lck: SDSpinLock = SDSpinLock()
    private var _notify: [NotifyType] = []
    
    private var _result: Result! = nil
    
    private init(_ queue: dispatch_queue_t) {
        self.queue = queue
    }
    
    /// Create a SDTask and compute block with specific queue.
    public init(queue: dispatch_queue_t, block: () -> Result) {
        self.queue = queue
        self.submit(block)
    }
    
    /// Create a SDTask and compute block with default queue.
    public init(block: () -> Result) {
        self.queue = SDThreadDefaultDispatchQueue
        self.submit(block)
    }
}

extension SDTask {
    
    private func notify() {
        self._lck.synchronized {
            self._notify.forEach { $0() }
            self._notify = []
        }
    }
    private func submit(block: () -> Result) {
        dispatch_group_async(group, queue) {
            self._result = block()
            defer { self.signal() }
        }
        dispatch_group_notify(group, queue, self.notify)
    }
    private func signal() {
        dispatch_semaphore_signal(self.sem)
    }
    
    /// Return `true` iff task is completed.

            dispatch_semaphore_wait(self.sem, DISPATCH_TIME_FOREVER)
            defer { dispatch_semaphore_signal(self.sem) }
        }
        return self._result!
    }
}

