Last active
February 2, 2021 17:46
-
-
Save swimauger/816f2b6100b9e5691cb19ed7472ac19f to your computer and use it in GitHub Desktop.
UUID Generator : Using Generators and yield
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
// Create a UUID Generator | |
function* UUIDGenerator() { | |
for (let i = 0; true; i++) { | |
yield i; | |
} | |
} | |
// Initialize UUID Generator | |
const uuid = UUIDGenerator(); | |
// Call next to get new uuid | |
console.log(uuid.next().value) // 0 | |
console.log(uuid.next().value) // 1 | |
console.log(uuid.next().value) // 2 | |
console.log(uuid.next().value) // 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment