Understanding Promise (1)

You need to pass a new Promise actuator (function) function takes two parameters resolve reject
The default state is committed to promise to call pengding resolve for success reject indicate failure
Each has an instance method then promise
We can wait for the state => state success / failure status but not from the success / failure state to a failure / success
 
 
P = the let new new Promise (function (Resolve, Reject) { 
the console.log ( ' starts running ' ); 
Resolve ( ' Valentine to ' ); 
Reject ( ' To ' ); 
}) 
p.then ((value) = > { 
the console.log ( ' Success ' , value) 
}, (reason) => { 
the console.log ( ' erroe ' , reason) 
}); 
the console.log ( ' end of run ' )

run:

[Running] node "d:\码云\zhufengjiagoukecheng\promise\promise-apply.js"
To start running
End of run
Valentine's Day to success

[Done] exited with code=0 in 0.388 seconds
 
Although we know that we can call reject instantiated Promise in ( 'to'); but it does not print out from here, we know that when we => Success Success from waiting => failed the state does not perform
 

 

Guess you like

Origin www.cnblogs.com/guangzhou11/p/11298993.html