Complex promise/task handling utility.