OK, so we have now seen that with a little bit of runtime hackery we can get access to a âtask enqueue global hookâ that is completely public and even apart of Swiftâs ABI, but just isnât easily accessible. But, once we do have a handle on the hook, then we have the opportunity to be notified anytime an async unit of work is scheduled to be performed.
So, what can we do with this?
Well, we can completely alter the manner in which jobs are enqueued. Right now we are just turning around and feeding the job back to the original enqueuer, which means the behavior is unchanged from the default. But we do have the ability to send those jobs to a different executor, such as a custom executor, or even serialize all the jobs onto the main executor.
Letâs take a look.