Originally created by @seanliu1 on GitHub (Feb 19, 2020).
I have a question regarding perform async function, I looked into the source code, but still not very clear for me. Here are code samples.
group.enter()
dataStack.perform(asynchronous: {(transaction) in
var p = transaction.create(Into<Person>())
p.id = 1
p.name = "test"
}, completion {
group.leave()
}
group.enter()
dataStack.perform(asynchronous: {(transaction) in
var p = try transaction.fetchOne(From<Person>().where(\Person.id == Int64(1))
// can we guarantee we can read P from the previous insertion
}, completion {
group.leave()
}
in the second group.enter, if we fetchOne, can we get the object we just inserted.
Originally created by @seanliu1 on GitHub (Feb 19, 2020).
I have a question regarding perform async function, I looked into the source code, but still not very clear for me. Here are code samples.
```
group.enter()
dataStack.perform(asynchronous: {(transaction) in
var p = transaction.create(Into<Person>())
p.id = 1
p.name = "test"
}, completion {
group.leave()
}
group.enter()
dataStack.perform(asynchronous: {(transaction) in
var p = try transaction.fetchOne(From<Person>().where(\Person.id == Int64(1))
// can we guarantee we can read P from the previous insertion
}, completion {
group.leave()
}
```
in the second group.enter, if we fetchOne, can we get the object we just inserted.
adam
added the question label 2025-12-29 15:28:42 +01:00
No, you can't. As the method name suggests, that is an asynchronous transaction. In fact, transactions run a serial asynchronous queue, so you don't really need your DispatchGroup there.
You can fetch the first created Person from inside the first transaction's completion, and also from inside the second transaction's asynchronous closure.
@JohnEstropia commented on GitHub (Feb 20, 2020):
No, you can't. As the method name suggests, that is an asynchronous transaction. In fact, transactions run a serial asynchronous queue, so you don't really need your `DispatchGroup` there.
You can fetch the first created `Person` from inside the first transaction's `completion`, and also from inside the second transaction's `asynchronous` closure.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @seanliu1 on GitHub (Feb 19, 2020).
I have a question regarding perform async function, I looked into the source code, but still not very clear for me. Here are code samples.
in the second group.enter, if we fetchOne, can we get the object we just inserted.
@JohnEstropia commented on GitHub (Feb 20, 2020):
No, you can't. As the method name suggests, that is an asynchronous transaction. In fact, transactions run a serial asynchronous queue, so you don't really need your
DispatchGroupthere.You can fetch the first created
Personfrom inside the first transaction'scompletion, and also from inside the second transaction'sasynchronousclosure.@seanliu1 commented on GitHub (Feb 20, 2020):
Thanks, sorry I mean in the second transaction's async closure.