Add handling of promises returned from callbacks

This enables chaining of multiple asynchronous tasks.