@@ -77,6 +77,23 @@ class DatasyncManager {
7777 }
7878 }
7979 // TODO: Add logic to sync Way
80+ for (key, way) in waysToSync {
81+ var payload = way. asOSMWay ( )
82+ // update the way
83+ let result = await syncWay ( way: & payload)
84+ switch result{
85+ case . success( let isFinished) :
86+ print ( " Synced \( payload) " )
87+ DispatchQueue . main. async {
88+ // your code here
89+ self . dbInstance. assignChangesetId ( obj: key, changesetId: payload. changeset)
90+ }
91+
92+ case . failure( let error) :
93+ print ( " Failed to sync \( payload) " )
94+ }
95+
96+ }
8097 isSynching = false
8198
8299 }
@@ -126,6 +143,16 @@ class DatasyncManager {
126143 }
127144 }
128145
146+ // utility function to act as substitute for osmConnection functions
147+ func updateWay( way: inout OSMWay ) async -> Result < Int , Error > {
148+ await withCheckedContinuation { continuation in
149+ osmConnection. updateWay ( way: & way, tags: way. tags) { result in
150+ continuation. resume ( returning: result)
151+ }
152+ }
153+ }
154+
155+
129156
130157 /**
131158 Syncs the node along with the updated
@@ -149,4 +176,24 @@ class DatasyncManager {
149176 return . failure( error)
150177 }
151178 }
179+
180+ func syncWay( way: inout OSMWay ) async -> Result < Bool , Error > {
181+ do {
182+ // open changeset
183+ let changesetId = try await openChangeset ( ) . get ( )
184+ // update node
185+ way. changeset = changesetId
186+ // close changeset
187+ let newVersion = try await updateWay ( way: & way) . get ( )
188+ way. version = newVersion
189+ // Give back the new version and other stuff.
190+ let closeResult = try await closeChangeset ( id: String ( changesetId) ) . get ( )
191+
192+ return . success( true )
193+
194+ } catch ( let error) {
195+ print ( error)
196+ return . failure( error)
197+ }
198+ }
152199}
0 commit comments