DEV Community

Cover image for Safe assignment (?=) alternative for promises
BlobKat
BlobKat

Posted on

Safe assignment (?=) alternative for promises

Promise.prototype.safe = function(){
  return this.then(
    res => [null, res],
    err = [err, null]
  );
}

const [err, res] = await fetch("https://blobk.at/").safe()
Enter fullscreen mode Exit fullscreen mode

Top comments (0)