std::async won’t spawn a new thread when return value is not stored

From just::thread documentation: If policy is std::launch::async then runs INVOKE(fff,xyz…) on its own thread. The returned std::future will become ready when this thread is complete, and will hold either the return value or exception thrown by the function invocation. The destructor of the last future object associated with the asynchronous state of the returned std::future … Read more

Wait For Asynchronous Operation To Complete in Swift

you have to pass your async function the handler to call later on: func application(application: UIApplication!, performFetchWithCompletionHandler completionHandler: ((UIBackgroundFetchResult) -> Void)!) { loadShows(completionHandler) } func loadShows(completionHandler: ((UIBackgroundFetchResult) -> Void)!) { //…. //DO IT //…. completionHandler(UIBackgroundFetchResult.NewData) println(“Background Fetch Complete”) } OR (cleaner way IMHO) add an intermediate completionHandler func application(application: UIApplication!, performFetchWithCompletionHandler completionHandler: ((UIBackgroundFetchResult) -> Void)!) … Read more

Calling TaskCompletionSource.SetResult in a non blocking manner

I’ve discovered that TaskCompletionSource.SetResult(); invokes the code awaiting the task before returning. In my case that result in a deadlock. Yes, I have a blog post documenting this (AFAIK it’s not documented on MSDN). The deadlock happens because of two things: There’s a mixture of async and blocking code (i.e., an async method is calling … Read more

ReaderWriterLockSlim and async\await

ReaderWriterLockSlim is a thread-affine lock type, so it usually cannot be used with async and await. You should either use SemaphoreSlim with WaitAsync, or (if you really need a reader/writer lock), use my AsyncReaderWriterLock from AsyncEx or Stephen Toub’s AsyncReaderWriterLock.