Giter Club home page Giter Club logo

ios-bank-manager's Introduction

은행창구 매니저

목차

  1. 소개
  2. 팀원
  3. 타임라인
  4. UML
  5. 실행 화면
  6. 트러블 슈팅
  7. 참고 링크

1. 소개

3명의 은행원이 10~30명의 손님을 처리

2. 팀원

Kiseok

3. 타임라인

프로젝트 기간: 23.11.13 ~ 23.11.24

날짜 내용
23.11.13 Linked List 구현 및 CustomerQueue 구현
23.11.14 코드 컨벤션 수정 및 리팩토링
23.11.15 Customer타입 구현
BankClerk타입 구현
Bank타입 구현
BankManager타입 구현
23.11.16 은행 앱 동작 구현
코드 컨벤션 수정 및 리팩토링
23.11.17 코드 컨벤션 수정 및 리팩토링
23.11.20 CustomerProtocol 구현
코드 컨벤션 수정 및 리팩토링
23.11.21 Concurrency 공부
23.11.22 Concurrency 공부
23.11.23 BankingCategory타입 구현
23.11.24 은행 앱 동작 구현

4. UML

스크린샷 2023-11-25 오후 10 23 03

5. 실행 화면

시작 종료
은행 시작 은행 종료

6. 트러블 슈팅

비동기 로직 관련

1. 은행 업무가 끝나기 전에 은행 종료멘트가 출력되는 문제

task group을 이용하여 하나의 Task 생성 후 while문 안에 각각의 child task를 생성 후 bankClerk들이 업무를 하도록 구현. while문 바깥에 close메서드를 호출하여 while문이 끝나야 실행되도록 구현

코드
Task {
    let taskStart = CFAbsoluteTimeGetCurrent()
    while depositLine.hasCustomer != 0 || loanLine.hasCustomer != 0 {
        await withTaskGroup(of: Void.self) { group in
            group.addTask {
                guard let loanCustomer = loanLine.dequeue() else {
                    return
                }
                await firstBankClerk.startTask(with: loanCustomer)
                    }
                    
            group.addTask {
                guard let depositCustomer = depositLine.dequeue() else {
                    return
                }
                await secondBankClerk.startTask(with: depositCustomer)
            }
                    
            group.addTask {
                guard let depositCustomer = depositLine.dequeue() else {
                    return
                }
                await thirdBankClerk.startTask(with: depositCustomer)
            }
        }
    }
    let taskEnd = CFAbsoluteTimeGetCurrent() - taskStart
    close(time: taskEnd)
    NotificationCenter.default.post(
                name: Bank.notificationName,
                object: nil
            )
}

2. 은행 업무가 모두 종료되기 전 시작 메뉴가 출력되는 문제

  • NotificationCenter를 통하여 은행업무가 종료되는 시점에 post하고 addObserver를 통해 시작 메뉴를 출력하도록 구현하는 방식
코드
let taskEnd = CFAbsoluteTimeGetCurrent() - taskStart
            
close(time: taskEnd)
NotificationCenter.default.post(
    name: Bank.notificationName,
    object: nil
)
case "1":
    bank.open()
    NotificationCenter.default.addObserver(
        forName: Bank.notificationName,
        object: nil,
        queue: nil) { _ in
            start()
        }
  • Escaping Closure를 활용하여 메뉴 출력하는 함수를 전달하도록 구현하는 방식
코드
    public func open(_ completion: @escaping () -> Void) {
        bankManager.giveWaitingTicketAndLineUp(
            customerNumber: customerNumber,
            depositLine: depositLine,
            loanLine: loanLine
        )

        bankClerkTask(completion)
    }
    
    private func bankClerkTask(_ completion: @escaping () -> Void) {
        Task {
            let taskStart = CFAbsoluteTimeGetCurrent()
            while depositLine.hasCustomer != 0 || loanLine.hasCustomer != 0 {
                await withTaskGroup(of: Void.self) { group in
                    group.addTask {
                        guard let loanCustomer = loanLine.dequeue() else {
                            return
                        }
                        await firstBankClerk.startTask(with: loanCustomer)
                    }
                    
                    group.addTask {
                        guard let depositCustomer = depositLine.dequeue() else {
                            return
                        }
                        await secondBankClerk.startTask(with: depositCustomer)
                    }
                    
                    group.addTask {
                        guard let depositCustomer = depositLine.dequeue() else {
                            return
                        }
                        await thirdBankClerk.startTask(with: depositCustomer)
                    }
                }
            }
            let taskEnd = CFAbsoluteTimeGetCurrent() - taskStart
            
            close(time: taskEnd)
            completion()
        }
    }
case "1":
    bank.open {
        start()
    }

NotificationCenter는 여러 곳에 전파하는 경우에 더 적합하다고 판단
지금 프로젝트 상 여러 곳에 전파 할 상황은 없다고 생각하여 escaping closure를 활용하는 방식으로 구현


RunLoop 관련

1. 은행개점 메뉴 선택 시 프로그램이 바로 종료되는 문제

해당 현상이 일어난 이유에 대한 개인적인 생각

Main Thread는 애플리케이션의 프레임워크가 자동으로 Run Loop를 생성하고 실행시키지만 다른 스레드들은 개발자가 명시적으로 실행시켜줘야하기 때문

해결 방법

RunLoop.current.run() 메서드를 활용하여 정상 작동하도록 구현

7. 참고 링크

Swift 공식문서 RunLoop
Apple Documentation Archive: Run Loops
Point Free Concurrency
Swift 공식문서 Concurrency
야곰 닷넷 스위프트 동시성 프로그래밍

ios-bank-manager's People

Contributors

carti1108 avatar soo941226 avatar yagom avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.