@@ -120,123 +120,128 @@ final class KTViewModelBuilderTests: XCTestCase {
120120 self.viewModelStore.get(key: " MainScreenViewModelKey " ) as! MainScreenViewModel
121121 }
122122
123+ private var jobs = [Task<(), Never>]()
124+
123125 @MainActor func start() async {
124- await withTaskGroup(of: (Void).self) {
125- $0.addTask { @MainActor [weak self] in
126- for await value in self!.instance.stringData where self != nil {
127- if value != self?.stringData {
128- #if DEBUG
129- print( " UPDATING TO VIEW stringData : " + String(describing: value))
130- #endif
131- self?.stringData = value
132- }
126+ jobs.append(Task { [weak self] in
127+ for await value in self!.instance.stringData where self != nil {
128+ if value != self?.stringData {
129+ #if DEBUG
130+ print( " UPDATING TO VIEW stringData : " + String(describing: value))
131+ #endif
132+ self?.stringData = value
133133 }
134134 }
135- $0.addTask { @MainActor [weak self] in
136- for await value in self!.instance.intNullableData where self != nil {
137- if value?.intValue != self?.intNullableData {
138- #if DEBUG
139- print( " UPDATING TO VIEW intNullableData : " + String(describing: value))
140- #endif
141- self?.intNullableData = value?.intValue
142- }
135+ })
136+ jobs.append(Task { [weak self] in
137+ for await value in self!.instance.intNullableData where self != nil {
138+ if value?.intValue != self?.intNullableData {
139+ #if DEBUG
140+ print( " UPDATING TO VIEW intNullableData : " + String(describing: value))
141+ #endif
142+ self?.intNullableData = value?.intValue
143143 }
144144 }
145- $0.addTask { @MainActor [weak self] in
146- for await value in self!.instance.randomValue where self != nil {
147- if value.doubleValue != self?.randomValue {
148- #if DEBUG
149- print( " UPDATING TO VIEW randomValue : " + String(describing: value))
150- #endif
151- self?.randomValue = value.doubleValue
152- }
145+ })
146+ jobs.append(Task { [weak self] in
147+ for await value in self!.instance.randomValue where self != nil {
148+ if value.doubleValue != self?.randomValue {
149+ #if DEBUG
150+ print( " UPDATING TO VIEW randomValue : " + String(describing: value))
151+ #endif
152+ self?.randomValue = value.doubleValue
153153 }
154154 }
155- $0.addTask { @MainActor [weak self] in
156- for await value in self!.instance.entityData where self != nil {
157- if value != self?.entityData {
158- #if DEBUG
159- print( " UPDATING TO VIEW entityData : " + String(describing: value))
160- #endif
161- self?.entityData = value
162- }
155+ })
156+ jobs.append(Task { [weak self] in
157+ for await value in self!.instance.entityData where self != nil {
158+ if value != self?.entityData {
159+ #if DEBUG
160+ print( " UPDATING TO VIEW entityData : " + String(describing: value))
161+ #endif
162+ self?.entityData = value
163163 }
164164 }
165- $0.addTask { @MainActor [weak self] in
166- for await value in self!.instance.bidirectionalString where self != nil {
167- if value != self?.bidirectionalString {
168- #if DEBUG
169- print( " UPDATING TO VIEW bidirectionalString : " + String(describing: value))
170- #endif
171- self?.bidirectionalString = value
172- }
165+ })
166+ jobs.append(Task { [weak self] in
167+ for await value in self!.instance.bidirectionalString where self != nil {
168+ if value != self?.bidirectionalString {
169+ #if DEBUG
170+ print( " UPDATING TO VIEW bidirectionalString : " + String(describing: value))
171+ #endif
172+ self?.bidirectionalString = value
173173 }
174174 }
175- $0.addTask { @MainActor [weak self] in
176- for await value in self!.instance.bidirectionalInt where self != nil {
177- if value?.intValue != self?.bidirectionalInt {
178- #if DEBUG
179- print( " UPDATING TO VIEW bidirectionalInt : " + String(describing: value))
180- #endif
181- self?.bidirectionalInt = value?.intValue
182- }
175+ })
176+ jobs.append(Task { [weak self] in
177+ for await value in self!.instance.bidirectionalInt where self != nil {
178+ if value?.intValue != self?.bidirectionalInt {
179+ #if DEBUG
180+ print( " UPDATING TO VIEW bidirectionalInt : " + String(describing: value))
181+ #endif
182+ self?.bidirectionalInt = value?.intValue
183183 }
184184 }
185- $0.addTask { @MainActor [weak self] in
186- for await value in self!.instance.bidirectionalBoolean where self != nil {
187- if value.boolValue != self?.bidirectionalBoolean {
188- #if DEBUG
189- print( " UPDATING TO VIEW bidirectionalBoolean : " + String(describing: value))
190- #endif
191- self?.bidirectionalBoolean = value.boolValue
192- }
185+ })
186+ jobs.append(Task { [weak self] in
187+ for await value in self!.instance.bidirectionalBoolean where self != nil {
188+ if value.boolValue != self?.bidirectionalBoolean {
189+ #if DEBUG
190+ print( " UPDATING TO VIEW bidirectionalBoolean : " + String(describing: value))
191+ #endif
192+ self?.bidirectionalBoolean = value.boolValue
193193 }
194194 }
195- $0.addTask { @MainActor [weak self] in
196- for await value in self!.instance.bidirectionalLong where self != nil {
197- if value.int64Value != self?.bidirectionalLong {
198- #if DEBUG
199- print( " UPDATING TO VIEW bidirectionalLong : " + String(describing: value))
200- #endif
201- self?.bidirectionalLong = value.int64Value
202- }
195+ })
196+ jobs.append(Task { [weak self] in
197+ for await value in self!.instance.bidirectionalLong where self != nil {
198+ if value.int64Value != self?.bidirectionalLong {
199+ #if DEBUG
200+ print( " UPDATING TO VIEW bidirectionalLong : " + String(describing: value))
201+ #endif
202+ self?.bidirectionalLong = value.int64Value
203203 }
204204 }
205- $0.addTask { @MainActor [weak self] in
206- for await value in self!.instance.bidirectionalDouble where self != nil {
207- if value.doubleValue != self?.bidirectionalDouble {
208- #if DEBUG
209- print( " UPDATING TO VIEW bidirectionalDouble : " + String(describing: value))
210- #endif
211- self?.bidirectionalDouble = value.doubleValue
212- }
205+ })
206+ jobs.append(Task { [weak self] in
207+ for await value in self!.instance.bidirectionalDouble where self != nil {
208+ if value.doubleValue != self?.bidirectionalDouble {
209+ #if DEBUG
210+ print( " UPDATING TO VIEW bidirectionalDouble : " + String(describing: value))
211+ #endif
212+ self?.bidirectionalDouble = value.doubleValue
213213 }
214214 }
215- $0.addTask { @MainActor [weak self] in
216- for await value in self!.instance.bidirectionalFloat where self != nil {
217- if value.floatValue != self?.bidirectionalFloat {
218- #if DEBUG
219- print( " UPDATING TO VIEW bidirectionalFloat : " + String(describing: value))
220- #endif
221- self?.bidirectionalFloat = value.floatValue
222- }
215+ })
216+ jobs.append(Task { [weak self] in
217+ for await value in self!.instance.bidirectionalFloat where self != nil {
218+ if value.floatValue != self?.bidirectionalFloat {
219+ #if DEBUG
220+ print( " UPDATING TO VIEW bidirectionalFloat : " + String(describing: value))
221+ #endif
222+ self?.bidirectionalFloat = value.floatValue
223223 }
224224 }
225- $0.addTask { @MainActor [weak self] in
226- for await value in self!.instance.bidirectionalUnit where self != nil {
227- if value.uintValue != self?.bidirectionalUnit {
228- #if DEBUG
229- print( " UPDATING TO VIEW bidirectionalUnit : " + String(describing: value))
230- #endif
231- self?.bidirectionalUnit = value.uintValue
232- }
225+ })
226+ jobs.append(Task { [weak self] in
227+ for await value in self!.instance.bidirectionalUnit where self != nil {
228+ if value.uintValue != self?.bidirectionalUnit {
229+ #if DEBUG
230+ print( " UPDATING TO VIEW bidirectionalUnit : " + String(describing: value))
231+ #endif
232+ self?.bidirectionalUnit = value.uintValue
233233 }
234234 }
235- }
235+ })
236236 }
237237
238238 deinit {
239+ self.jobs.forEach {
240+ $0.cancel()
241+ }
242+ self.jobs.removeAll()
239243 self.viewModelStore.clear()
244+ print( " DEINIT \( self ) " )
240245 }
241246 }
242247 """ ,
0 commit comments