swift - Are there performance differences for saveInBackground v saveEventually? -
is there reason use saveinbackground
instead of saveeventually
? both have callbacks available. there difference in performance or functionality? exact same function saveeventually
having network check in it?
my understanding same because they're compared in docs docs don't explicitly state that. saveinbackground
pushed higher priority thread saveeventually
or thread same?
update:
as there performance differences mikeg notes below made simple fallback save method in case situations. employ everywhere run normal save operation. saveinbackground
, fallback saveeventually
:
func saveinbackgroundifnotsuccesssaveeventually(object: pfobject, completion: (() -> ())?) { object.saveinbackgroundwithblock({ (success, error) -> void in if !success { object.saveeventually({ (success, error) -> void in if success { completion?() } if error != nil { nslog(error!.localizeddescription) } }) } else if success { completion?() } if error != nil { nslog(error!.localizeddescription) } })
}
the 2 functions different. saveinbackground
performs save asynchronously. means calls save function, , returns calling thread functionality may continue without having wait save function complete , return. have been using saveinbackground
in app , have literally done hundreds of tests , long internet connection available, function completed within 3 seconds max, within 1 second. how function behaves when no internet connection available unsure, if in situation in unsure if connection available, need make save, go saveeventually()
.
saveeventually
on other hand perform save @ unspecified time in future. if internet connection unavailable, wait until connection available , perform save. believe, though not positive, function dispatched queue has quality of service background
, not high priority task, can put off until resources available @ unspecified time in future. take anywhere seconds minutes hours suppose, if connection unavailable long.
edit: forgot answer question directly, "are there performance differences...". answer yes!
Comments
Post a Comment