 	fileprivate var downloadInProgressSignal: Signal<Bool, NoError>?
 	fileprivate var downloadInProgressObserver: Signal<Bool, NoError>.Observer?
 	fileprivate let saveQueue: DispatchQueue
+	fileprivate let taskLockQueue: DispatchQueue
 	
 	lazy var fileCacheUrl: URL = { () -> URL in
 		var fileDir: URL? = nil

		urlSession?.invalidateAndCancel()
	}
	
	internal func isFileCached(_ file:File) -> Bool {
		return cachedUrl(file:file).fileExists()
	}

	@discardableResult func flushCache(workspace:Workspace) {
		
	}
	

	/// - Returns: a signal producer that returns the file data or an error
	public func contents(of file: File) -> SignalProducer<Data, FileError> {
		return SignalProducer<Data, FileError>() { observer, _ in
			self.taskLockQueue.sync {
				guard nil == self.downloadInProgressSignal else
				{
					//download is in progress. wait until completed. use ! because should not change while taskLock is locked
					_ = self.downloadInProgressSignal!.observeCompleted {
						self.loadContents(file: file, observer: observer)
					}
					return
				}
				//want to release lock before actually load the contents
				DispatchQueue.main.async {
					self.loadContents(file: file, observer: observer)
				}
			}
		}
	}
