Last active
August 14, 2016 10:54
-
-
Save slorber/aa6b6e0390c1b87db4eb412219b929b0 to your computer and use it in GitHub Desktop.
Future/promise vs JS generators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function* findOldestKnownFatherSideAncestor(person) { | |
let currentPerson = person; | |
while (currentPerson.fatherId) { | |
currentPerson = yield call(PersonAPI.getById,currentPerson.fatherId); | |
} | |
return currentPerson | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def findOldestKnownFatherSideAncestor(person: Person): Future[Person] = { | |
person.fatherId match { | |
case None => Future(person) | |
case Some(id) => PersonAPI.getById(id).flatMap(findOldestKnownFatherSideAncestor) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment