Wraps a function in asynchronous mode and make it able to emit events.