Skip to content

Instantly share code, notes, and snippets.

@Nahiduzzaman
Created April 29, 2017 19:03
Show Gist options
  • Select an option

  • Save Nahiduzzaman/fb19759409c54d683266084c12c3cda4 to your computer and use it in GitHub Desktop.

Select an option

Save Nahiduzzaman/fb19759409c54d683266084c12c3cda4 to your computer and use it in GitHub Desktop.

Revisions

  1. Nahiduzzaman created this gist Apr 29, 2017.
    14 changes: 14 additions & 0 deletions promise.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    let myFirstPromise = new Promise((resolve, reject) => {
    // We call resolve(...) when what we were doing async succeeded, and reject(...) when it failed.
    // In this example, we use setTimeout(...) to simulate async code.
    // In reality, you will probably be using something like XHR or an HTML5 API.
    setTimeout(function(){
    resolve("Good To go"); // Yay! Everything went well!
    }, 1000);
    });

    myFirstPromise.then((response) => {
    // successMessage is whatever we passed in the resolve(...) function above.
    // It doesn't have to be a string, but if it is only a succeed message, it probably will be.
    console.log(response);
    });