Skip to content

Commit

Permalink
refactor(Queue): 함수 분리 및 로그 출력
Browse files Browse the repository at this point in the history
  • Loading branch information
Jong1co committed Apr 27, 2024
1 parent ad058a4 commit 4a18e30
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/service/Queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,25 @@ export class BankAccountServiceQueueImpl implements BankAccountServiceQueue {
return func;
}

private isInvalidRequest = (node: BankAccountQueueNode, id: number) => {
return node.id === id && node.action === "deposit";
};

// 재귀함수 사용
async exec() {
const { func, id } = this.queue[0];

await sleep(0);

if (!this.isValid(id)) {
//유효하지 않은 횟수만큼 콘솔 출력
this.queue.forEach((node) => {
this.isInvalidRequest(node, id) &&
console.log("입금 요청이 동시에 발생했습니다.");
});

this.queue = this.queue.filter(
(node) => !(node.id === id && node.action === "deposit")
(node) => !this.isInvalidRequest(node, id)
);

if (this.queue.length > 0) {
Expand Down

0 comments on commit 4a18e30

Please sign in to comment.