Code based on current make-promise, with some optimizations.