Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Real-world promise demo #18

Open
raq929 opened this issue Feb 28, 2017 · 0 comments
Open

Real-world promise demo #18

raq929 opened this issue Feb 28, 2017 · 0 comments

Comments

@raq929
Copy link
Contributor

raq929 commented Feb 28, 2017

I did this in 016, and @jrhorn424 thinks it (or something similar) maybe should be added to the lesson.

I wrote an IOU ("Yen owes me keys") on a piece of paper. I gave my keys to Yen, and explained that the piece of paper is now the "Promise". I can't drive home until I get my keys back, and getting my keys back can set things in motion. A failure to get my keys will cause a different course of action.

I made a psuedo-code promise:

new Promise((resolve, reject) {
  if(time > 5 pm) {
     reject(error)
  }

 resolve(keys)
})

And when it became relevant, a promise chain:

keysPromise()
  .then(putKeysInCoat)
  .then(putOnCoat)
  .then(goToCar)
  .then(driveHome)
  .catch(callYen)

And I explained that each of these has a return value that is passed to the next one. (With arrows and the values).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant