{"action":"closed","issue":{"url":"https://api.github.com/repos/realm/realm-cocoa/issues/1357","labels_url":"https://api.github.com/repos/realm/realm-cocoa/issues/1357/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-cocoa/issues/1357/comments","events_url":"https://api.github.com/repos/realm/realm-cocoa/issues/1357/events","html_url":"https://github.com/realm/realm-cocoa/issues/1357","id":54808768,"number":1357,"title":"Auto-refreshing realms and notifications possible race condition","user":{"login":"BrentleyJones","id":158658,"avatar_url":"https://avatars.githubusercontent.com/u/158658?v=3","gravatar_id":"","url":"https://api.github.com/users/BrentleyJones","html_url":"https://github.com/BrentleyJones","followers_url":"https://api.github.com/users/BrentleyJones/followers","following_url":"https://api.github.com/users/BrentleyJones/following{/other_user}","gists_url":"https://api.github.com/users/BrentleyJones/gists{/gist_id}","starred_url":"https://api.github.com/users/BrentleyJones/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BrentleyJones/subscriptions","organizations_url":"https://api.github.com/users/BrentleyJones/orgs","repos_url":"https://api.github.com/users/BrentleyJones/repos","events_url":"https://api.github.com/users/BrentleyJones/events{/privacy}","received_events_url":"https://api.github.com/users/BrentleyJones/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/realm/realm-cocoa/labels/pending","name":"pending","color":"ededed"}],"state":"closed","locked":false,"assignee":{"login":"segiddins","id":1946610,"avatar_url":"https://avatars.githubusercontent.com/u/1946610?v=3","gravatar_id":"","url":"https://api.github.com/users/segiddins","html_url":"https://github.com/segiddins","followers_url":"https://api.github.com/users/segiddins/followers","following_url":"https://api.github.com/users/segiddins/following{/other_user}","gists_url":"https://api.github.com/users/segiddins/gists{/gist_id}","starred_url":"https://api.github.com/users/segiddins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/segiddins/subscriptions","organizations_url":"https://api.github.com/users/segiddins/orgs","repos_url":"https://api.github.com/users/segiddins/repos","events_url":"https://api.github.com/users/segiddins/events{/privacy}","received_events_url":"https://api.github.com/users/segiddins/received_events","type":"User","site_admin":false},"milestone":null,"comments":6,"created_at":"2015-01-19T20:30:29Z","updated_at":"2015-02-03T22:57:56Z","closed_at":"2015-02-03T22:57:56Z","body":"I think I ran into a race condition regarding auto-refreshing realms and notifications.\r\n\r\nWhen I have a notification on a realm it causes it to be cached for that thread, which means that it follows the auto-refreshing rules when reading from it instead of always being the latest data (Something I hadn't encountered before I used notifications, since I throw away my realm objects after reading from them). When the notification comes through it causes it to auto-refresh, so the latest write data is available.\r\n\r\nThe way that I have been using realm is to write in a background thread, then post a block on the main thread to do something with the written data. Before registering for notifications my realm object would always have the latest data, because we would be on the next run loop and the realm object was fresh. Now with notifications I would not find my data available, since my block would run before the notification was posted to the cached realm object.\r\n\r\nFor now I've fixed this by calling `refresh` on any realm that I plan on reading from. This is not ideal, so I was hoping that there would be a way to ensure that the auto-refreshing happens before any block of mine is run. I assumed that after the `commitWriteTransaction` or `transactionWithBlock` any dispatch_async on the main thread would run on an updated realm."}}