Skip to content

Javascript Asynchronous Programming and Promises

Notifications You must be signed in to change notification settings

tkalatz/givePromises

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

givePromises

Javascript Asynchronous Programming and Promises, Never give promises ;) Javascript promises can blow your mind... but can make things better - as promises always

const givePromise = (gift) => {
  return new Promise( (r,f) => {
   r(gift);
   console.log("Promise Given for a new Gift!");
  })
}

const doYouRemember = (thought,seconds) => {
  return new Promise( (r,f) => {
  console.log(thought+" trying to remember...");
  setTimeout( function() {
    r("Promises are usually forgotten!"); 
	console.log(seconds+" seconds is too much thinking, for what you have promised and you cannot rethink.");
  }, seconds*1000) 
  })
} 

givePromise("A gift").then( gift => {
  return gift+" was ";
 })
 .then ( (result) => {
  return result+"promised but ";
 })
 .then( (thought) => doYouRemember(thought,3) )
 .then( result => {
	 console.log(result);
});

About

Javascript Asynchronous Programming and Promises

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published