Fix race condition
This commit is contained in:
parent
83561e1d1b
commit
c156313fee
@ -1,7 +1,5 @@
|
|||||||
package it.tdlight.common;
|
package it.tdlight.common;
|
||||||
|
|
||||||
import it.tdlight.jni.TdApi;
|
|
||||||
|
|
||||||
public abstract class CommonClientManager {
|
public abstract class CommonClientManager {
|
||||||
|
|
||||||
private static InternalClientManager getClientManager(String implementationName) {
|
private static InternalClientManager getClientManager(String implementationName) {
|
||||||
@ -34,8 +32,6 @@ public abstract class CommonClientManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static TelegramClient create(InternalClient internalClient) {
|
private static TelegramClient create(InternalClient internalClient) {
|
||||||
// Send a dummy request because @levlam is too lazy to fix race conditions in a better way
|
|
||||||
internalClient.send(new TdApi.GetAuthorizationState(), null, null);
|
|
||||||
return internalClient;
|
return internalClient;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,8 @@ public class InternalClient implements ClientEventsHandler, TelegramClient {
|
|||||||
UpdatesHandler updatesHandler,
|
UpdatesHandler updatesHandler,
|
||||||
ExceptionHandler updateExceptionHandler,
|
ExceptionHandler updateExceptionHandler,
|
||||||
ExceptionHandler defaultExceptionHandler) {
|
ExceptionHandler defaultExceptionHandler) {
|
||||||
|
clientInitializationLock.writeLock().lock();
|
||||||
|
try {
|
||||||
this.updateHandler = null;
|
this.updateHandler = null;
|
||||||
this.updatesHandler = new MultiHandler(updatesHandler, updateExceptionHandler);
|
this.updatesHandler = new MultiHandler(updatesHandler, updateExceptionHandler);
|
||||||
this.clientManager = clientManager;
|
this.clientManager = clientManager;
|
||||||
@ -51,6 +53,9 @@ public class InternalClient implements ClientEventsHandler, TelegramClient {
|
|||||||
this.clientId = NativeClientAccess.create();
|
this.clientId = NativeClientAccess.create();
|
||||||
|
|
||||||
clientManager.registerClient(clientId, this);
|
clientManager.registerClient(clientId, this);
|
||||||
|
} finally {
|
||||||
|
clientInitializationLock.writeLock().unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user