-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[2단계 - 자동차 경주 구현] 곤이(김기융) 미션 제출합니다. #40
Changes from 1 commit
33cefec
0ec45c5
7c6d40e
2e5ee3f
d85ed8d
d07d60e
d40330d
c719b10
69cc7eb
70163ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export function sleep(ms) { | ||
return new Promise((resolve, _) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 식별자명을 _ (언더바) 로 하는게 private이라는 의미로 쓸 수도 있고 사용 하신것 처럼 파라미터의 경우는 사용되지 않는 변수라는 의미로 쓸 수도 있고 언어차원에서 문법적으로 지원하는 언어도 있고 그저 관례적으로 쓰는 경우도 있고 다양합니다. |
||
setTimeout(() => { | ||
resolve(); | ||
}, ms); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아마 문제의 의도는 그저 코드 실행을 지연 시키라는게 아니라 결과를 비동기적으로 얻어서 사용하는 경험을 의도하지 않았을까 싶습니다.
이를테면 자동차가 앞으로 나가는데, 앞으로 나간 그 결과가 1초뒤에 온다는걸 가정하지 않았을까 싶습니다.
한 턴의 요청과 결과 사이에 로딩바가 도는걸테고요.
따라서 sleep 는 제거하고 this.getMoveCars() 의 반환이 프로미스여야 할 것 같습니다.
서버로부터 비동기적으로 데이터를 받아 화면에 그려내는 작업이 프론트 개발의 주를 이루기에 제가 만약 이런 문제를 냈다면 그런 의도였을것 같습니다.
문제 의도는 제 추측일뿐이니 혹시 확인 가능하시면 확인 해보고 하셔도 좋고 확인 필요없이 수정을 시도 해보셔도 좋을 것 같습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
문제의 의도를 곰곰이 생각해보니 말씀하신대로 getMovedCars가 프로미스를 반환하는 것이 맞다고 생각합니다!
따라서 startRacing에서 sleep을 사용하는 대신 getMovedCars에 새로운 프로미스를 반환하도록 하여 시간을 지연시키도록 코드를 다시 작성하였습니다. 서버로부터 비동기 데이터를 처리하기 위한 연습일 것 같다고 예시를 들어주셔서 잘 이해할 수 있었습니다. 감사합니다 :)