본문 바로가기

async

(3)
[Swift] 가장 간단한 Actor 샘플코드, Actor Counter swift concurrency 에 actor 라는 개념이 있다. 가장 간단하게 actor 를 사용하는 예제를 만들어 보았다. ( with a little help of gpt ) 횟수를 카운트 하는 매우 간단한 카운터 class/actor이다. 카운터를 생성해서, 동시에 수행되는 두 태스크에서 동시에 카운팅이 이루어진다. import Foundation actor MyActorCounter { var counter = 0 func incrementCounter() { counter += 1 } } class MyClassCounter { var counter = 0 func incrementCounter() { counter += 1 } } func testActorCounter() async -> V..
[Swift|번역] Process waitUntilExit 은 비동기 completion handler 와 같이 쓰지 않는다. https://stackoverflow.com/a/49541564 동기함수인 waitUntilExit() 은 비동기적 completion handler 와는 같이쓰기 어렵다. 비동기 completion handler 를 사용한다면, exit 을 기다리는 건 의미없는 일이다. --- pipe의 fileHandleForReading 을 클로져에서 사용하기 때문에 double free 에러가 발생하는 것일 수 있다. stdout 을 동기적으로 읽으라.
twisted counter 연습문제 http://krondo.com/?p=1333 여기에서 제시한 연습문제를 풀어봤다. 왠지 깔끔하지 않아보이는 코드이지만 남겨본다. class Countdown(object): MARKER_REF = '~!@#$%^&*()`,/+_|:;' # a counter is # c[0] : initial value # c[1] : count function counters = [ ] def add_counter(self, c, d): M = self.MARKER_REF marker_string = M[c%len(M)]*3 + M[d%len(M)]*3 idx = len(self.counters) def count(): if sum(map(lambda x : x[0], self.counters)) == 0: react..