@@ -70,13 +70,10 @@ public Task<Void> then(Task<Void> task) throws Exception {
70
70
71
71
@ Override
72
72
public Task <ParseInstallation > getAsync () {
73
- final ParseInstallation cachedCurrent ;
74
73
synchronized (mutex ) {
75
- cachedCurrent = currentInstallation ;
76
- }
77
-
78
- if (cachedCurrent != null ) {
79
- return Task .forResult (cachedCurrent );
74
+ if (currentInstallation != null ) {
75
+ return Task .forResult (currentInstallation );
76
+ }
80
77
}
81
78
82
79
return taskQueue .enqueue (new Continuation <Void , Task <ParseInstallation >>() {
@@ -85,26 +82,32 @@ public Task<ParseInstallation> then(Task<Void> toAwait) throws Exception {
85
82
return toAwait .continueWithTask (new Continuation <Void , Task <ParseInstallation >>() {
86
83
@ Override
87
84
public Task <ParseInstallation > then (Task <Void > task ) throws Exception {
88
- return store .getAsync ();
89
- }
90
- }).continueWith (new Continuation <ParseInstallation , ParseInstallation >() {
91
- @ Override
92
- public ParseInstallation then (Task <ParseInstallation > task ) throws Exception {
93
- ParseInstallation current = task .getResult ();
94
- if (current == null ) {
95
- current = ParseObject .create (ParseInstallation .class );
96
- current .updateDeviceInfo (installationId );
97
- } else {
98
- installationId .set (current .getInstallationId ());
99
- PLog .v (TAG , "Successfully deserialized Installation object" );
100
- }
101
-
102
85
synchronized (mutex ) {
103
- currentInstallation = current ;
86
+ if (currentInstallation != null ) {
87
+ return Task .forResult (currentInstallation );
88
+ }
104
89
}
105
- return current ;
90
+
91
+ return store .getAsync ().continueWith (new Continuation <ParseInstallation , ParseInstallation >() {
92
+ @ Override
93
+ public ParseInstallation then (Task <ParseInstallation > task ) throws Exception {
94
+ ParseInstallation current = task .getResult ();
95
+ if (current == null ) {
96
+ current = ParseObject .create (ParseInstallation .class );
97
+ current .updateDeviceInfo (installationId );
98
+ } else {
99
+ installationId .set (current .getInstallationId ());
100
+ PLog .v (TAG , "Successfully deserialized Installation object" );
101
+ }
102
+
103
+ synchronized (mutex ) {
104
+ currentInstallation = current ;
105
+ }
106
+ return current ;
107
+ }
108
+ }, ParseExecutors .io ());
106
109
}
107
- }, ParseExecutors . io () );
110
+ });
108
111
}
109
112
});
110
113
}
0 commit comments