hadle both sync and async functions