Code Monkey home page Code Monkey logo

Comments (2)

commitcomplete avatar commitcomplete commented on June 26, 2024

뷰모델에 있는 타이머의 1초가 반복될때마다 rx로 넘기는 것까지는 좋았다.
하지만 의외의 복병이 있었는데, 바로 테이블뷰와 타이머가 동시에 업데이트 되는 경우였다.
그냥 두면 타이머가 정상적으로 작동하지만 테이블을 스크롤 할 시에 스크롤이 끝날때 까지 타이머가 반복문을 실행하지 않는 것이었다.
예상되는 이유는 테이블을 업데이트 할때 사용하는 스레드가 무조건 메인스레드라 타이머를 감싸고 있는 스레드는 메인스레드를 제외한 다른 스레드여야 했던 것이다. 이에 흔히 알려진 dispatch를 이용하여 다른 스레드 들을 사용하였으나 해결하지 못하였고, 뷰를 분리하면 다른 스레드에서 돌아간다는 말을 듣고 테이블뷰를 분리하려는 시도까지 하였으나 실패로 돌아갔다.(타이머는 뷰모델에서 작동하고 있었기에)

그러다가 결국에는 타이머를 다른 스레드에서 돌리는 것만이 유일한 길임을 인정하고
https://stackoverflow.com/questions/27839973/how-to-move-timer-to-background-thread
타이머를 백그라운드에서 돌리는 방법을 찾게 되었다.
Run Loop라는 키워드를 얻어간다!

from cafe.

commitcomplete avatar commitcomplete commented on June 26, 2024

Run Loop 란 한 번의 실행 동안 내 쓰레드에 도착한 이벤트를 받고, 이에 대한 핸들러를 수행하는 객체임.
메인 스레드 같은 경우 run loop가 자동적으로 반복적으로 실행되지만, 메인 스레드가 아닌 다른 스레드의 경우 런루프가 생성되고 한번만 실행된다.
따라서 반복적으로 실행시켜주기위해서는 사용자가 임의로 런루프 객체를 받아와 run시켜주어야 한다.

from cafe.

Related Issues (20)

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.