two DispatchSourceTimers sharing one resource error, multithread task

前端 未结 1 1102
执念已碎
执念已碎 2021-01-28 06:57

I have to make a simple task - singleview app with two buttons and three treads -

Start Button :

create a thread T1 - the GPS location of the device is collected r

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-28 07:33

    In appendAndPost, you are appending result only if the count is less than maxData.

    But let’s imagine that you called this where you already had five items in the array. In that scenario, you start the request, but you’re never doing anything with the supplied value.

    I would advise appending the value regardless, and sending if the count hits the threshold:

    func appendAndPost(phoneInfo: String) {
        data.append(phoneInfo)
    
        if data.count >= maxData {
            // create your request and send it
    
            ...
    
            // reset `data`
    
            data = []
        }
    }
    

    0 讨论(0)
提交回复
热议问题