Add implementation of `Promise.guard()`, borrowed from `when`.