Closed martheli closed 7 years ago
You don’t store the result if getVersion to versionarray.
On 16 Jul 2017, at 09.08, martheli notifications@github.com wrote:
My code is as follows:
let backgroundBlock = Async.utility {
for serial in serialarray { self.getVersion(serial: serial) } } backgroundBlock.main { print (serialarray) print (versionarray) SwiftSpinner.hide() }
If I understand this right, getVersion should run in the background until it completes fully and then the second block should run and print out both of my arrays. Instead the first array gets printed but the second array comes up blank. I added a print inside of my getVersion function to see if it was working and I can see all the values being populated so it looks like the block is not waiting to complete before it prints the array out. Am I doing something wrong?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
@duemunk I added the getVersion function to my original post. Versionarray gets populated in the getVersion function.
I also tried the following:
let group = AsyncGroup()
group.utility {
for serial in serialarray
{
self.getVersion(serial: serial)
}
}
group.wait()
print (serialarray)
print (versionarray)
SwiftSpinner.hide()
Both prints are executing before getVersion finishes its loop to populate the array.
This is not an issue for Async. Please refer to GCD documentation and/or StackOverflow.
My code is as follows:
If I understand this right, getVersion should run in the background until it completes fully and then the second block should run and print out both of my arrays. Instead the first array gets printed but the second array comes up blank. I added a print inside of my getVersion function to see if it was working and I can see all the values being populated so it looks like the block is not waiting to complete before it prints the array out. Am I doing something wrong?
The getVersion function is as follows: