Added an option to perform a block on a main thread and wait