I am trying to verify the cancellation of a DispatchWork element on a Swift Playground, although there is an error during the first few milliseconds that I am not sure what it actually indicates, and I canβt tell if the error causes the cancellation, and not the cancel() method. ..
func testDispatchWorkItems() { let queue = DispatchQueue.global(qos: .userInitiated) var item: DispatchWorkItem? // create work item item = DispatchWorkItem { for i in 0 ... 100000 { if item!.isCancelled { break } print(i) } } // start it queue.async(execute: item!) // after three seconds, stop it queue.asyncAfter(deadline: .now() + 3) { item?.cancel() } } testDispatchWorkItems()
2016-10-26 11:14:33.898 com.apple.dt.Xcode.PlaygroundStub-macosx[30685:18567692] Error encountered communicating with Xcode: Error Domain=DVTPlaygroundCommunicationErrorDomain Code=1 "Cannot send data because stream is closed." UserInfo={NSLocalizedDescription=Cannot send data because stream is closed.}
Has anyone understood what this error indicates?
l'l'l source share