Skip to content

Commit e915e29

Browse files
author
David Skuza
committed
fix(sync): safely save on main thread
1 parent cda4f5d commit e915e29

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

Sync/Space.swift

+13-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ class Space {
3939
}
4040

4141
func save() throws {
42-
try DispatchQueue.main.sync {
43-
if context.hasChanges {
44-
try context.save()
42+
if Thread.isMainThread {
43+
try _save()
44+
} else {
45+
try DispatchQueue.main.sync {
46+
try _save()
4547
}
4648
}
4749
}
@@ -55,3 +57,11 @@ class Space {
5557
}
5658
}
5759
}
60+
61+
private extension Space {
62+
func _save() throws {
63+
if context.hasChanges {
64+
try context.save()
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)