Created
September 24, 2021 14:43
-
-
Save menangen/085a92240108b88d3ad3b0d3cebe5a8b to your computer and use it in GitHub Desktop.
Swift 5 GCD
This file contains hidden or 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
// | |
// main.swift | |
// dispatcher | |
// | |
// Created by menangen on 24.09.2021. | |
// | |
import Foundation | |
import Dispatch | |
print("Hello, Dispatch!") | |
let timerQ = DispatchQueue(label: "timer") | |
let udpQ = DispatchQueue(label: "udp") | |
let source = DispatchSource.makeUserDataAddSource(queue: udpQ) | |
source.setEventHandler(handler: { | |
print("EventHandler", Thread.current) | |
}) | |
source.activate() | |
timerQ.asyncAfter(wallDeadline: .now() + 1) { | |
print("async after", Thread.current) | |
source.add(data: 1) | |
} | |
sleep(2) | |
print("End") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment