ios - GCD Cancel and restart queue when button pressed again -


simply, have button adds queue, or believe that's how works - i've started use gcd. if press button twice in app, runs these 2 processes in parallel , progress bar races , forth between them, i'd stop other instances of queue , execute new 1 if makes sense, i've not got grips lingo...

@ibaction func makepi(_ sender: uibutton) {     piprogress.progress = 0.0     let queue1 = dispatchqueue(label: "com.appcoda.queue1", qos: dispatchqos.userinitiated)     queue1.async {         let currentamount = int(self.randnum.value)         var gcdcounter = 0          n in 1...currentamount {             if self.gcd(self.random(max: int(self.randrange.value)), self.random(max: int(self.randrange.value))) == 1{                 gcdcounter += 1             }             if n % 1000 == 0 {                 dispatchqueue.main.async {                     self.piprogress.setprogress(float(double(n)/double(currentamount)), animated: true)                 }             } else if n == currentamount {                 dispatchqueue.main.async {                     self.piprogress.setprogress(1.0, animated: true)                 }             }         }          let pifinal = sqrt(double((6/double((double(gcdcounter)/double(currentamount))))))         let roundedaccuracy: double = ((pifinal-double.pi)/double.pi*100).roundto(places: 6)          dispatchqueue.main.async {             self.pilabel.text = string(pifinal)             self.piaccuracy.text = "accuracy: \(roundedaccuracy)%"         }     } } 

i need other queue1.async ones stop...

p.s. if i've done obviously wrong, please ^^ thanks.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -