generate id with a generator function

generate id with a generator function

function* generateId() {
 let index = 1;
 while (true) {
  yield index++;
 }
}

const generateUserId = generateId();
const generateProdId = generateId();
// user id
console.log("user", generateUserId.next());
console.log("user", generateUserId.next());
console.log("user", generateUserId.next());

// product id

console.log("prod", generateProdId.next());
console.log("prod", generateProdId.next());
console.log("prod", generateProdId.next());

// output 
user { value: 1, done: false }
user { value: 2, done: false }
user { value: 3, done: false }
prod { value: 1, done: false }
prod { value: 2, done: false }
prod { value: 3, done: false }

// এখানে দেখুন প্রত্যেক টা ভেরিয়েবলের জন্য আলাদা আলাদা ID তৈরি করে দিয়েছে ।