Skip to content

Latest commit

 

History

History
18 lines (14 loc) · 497 Bytes

File metadata and controls

18 lines (14 loc) · 497 Bytes

let myPromise = new Promise(function(myResolve, myReject) { // "Producing Code" (May take some time)

myResolve(); // when successful myReject(); // when error });

// "Consuming Code" (Must wait for a fulfilled Promise) myPromise.then( function(value) { /* code if successful / }, function(error) { / code if some error */ } );

When the producing code obtains the result, it should call one of the two callbacks:

When Call Success myResolve(result value) Error myReject(error object)