This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let queue = DispatchQueue(label: "queue", attributes: .concurrent) | |
let workItem = DispatchWorkItem { | |
sleep(2) | |
print("done") | |
} | |
queue.async(execute: workItem) | |
workItem.notify(queue: .main) { | |
print("notify!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let queue = DispatchQueue(label: "queue", attributes: .concurrent) | |
let workItem = DispatchWorkItem { | |
sleep(3) | |
print("done") | |
} | |
queue.async(execute: workItem) | |
print("before waiting") | |
workItem.wait() | |
print("after waiting") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let queue = DispatchQueue(label: "queue", attributes: .concurrent) | |
let workItem = DispatchWorkItem { | |
print("done") | |
} | |
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) { | |
queue.async(execute: workItem) // not work | |
} | |
workItem.cancel() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let workItem = DispatchWorkItem { | |
sleep(1) | |
print("done") | |
} | |
workItem.perform() // Execute synchronously | |
print("after perfrom") | |
//done | |
//after perfrom |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
applyTwice :: (a -> a) -> a -> a | |
applyTwice f x = f (f x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Prelude> max 4 5 | |
5 | |
Prelude> (max 4) 5 | |
5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension String { | |
func isNumber() -> Bool { | |
let pattern = "^[\\d]+$" | |
guard let regex = try? NSRegularExpression(pattern: pattern) else { return false } | |
let matches = regex.matches(in: self, range: NSRange(location: 0, length: length)) | |
return matches.count > 0 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@available(iOS 10.0, *) | |
public enum NCWidgetDisplayMode : Int { | |
case compact // Fixed height | |
case expanded // Variable height | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let group = DispatchGroup() | |
let queue1 = DispatchQueue(label: "com.GCD.groupQueue1") | |
let queue2 = DispatchQueue(label: "com.GCD.groupQueue2") | |
let queue3 = DispatchQueue(label: "com.GCD.groupQueue3") | |
queue1.async(group: group) { | |
sleep(4) | |
print("excute queue1") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DegitObserver implements Observer { | |
public void update(NumberGenerator generator) { | |
System.out.println("DegitObserver:" + generator.getNumber()); | |
try { | |
Thread.sleep(100); | |
} catch (InterruptedException e) { | |
} | |
} | |
} |