Просмотр исходного кода

Make connectToComm synchronous.

Jason Grout 6 лет назад
Родитель
Сommit
d7ea1bb808
2 измененных файлов с 9 добавлено и 16 удалено
  1. 7 11
      packages/services/src/kernel/default.ts
  2. 2 5
      packages/services/src/kernel/kernel.ts

+ 7 - 11
packages/services/src/kernel/default.ts

@@ -636,24 +636,20 @@ class DefaultKernel implements Kernel.IKernel {
   /**
    * Connect to a comm, or create a new one.
    *
-   * TODO: should we change this to a synchronous function? There's nothing
-   * asynchronous about it now.
-   *
    * #### Notes
-   * If a client-side comm already exists, it is returned.
+   * If a client-side comm already exists with the given commId, it is returned.
    */
-  async connectToComm(targetName: string, commId?: string): Promise<Kernel.IComm> {
-    let id = commId || uuid();
-    if (this._comms.has(id)) {
-      return this._comms.get(id);
+  connectToComm(targetName: string, commId: string = uuid()): Kernel.IComm {
+    if (this._comms.has(commId)) {
+      return this._comms.get(commId);
     }
     let comm = new CommHandler(
       targetName,
-      id,
+      commId,
       this,
-      () => { this._unregisterComm(id); }
+      () => { this._unregisterComm(commId); }
     );
-    this._comms.set(id, comm);
+    this._comms.set(commId, comm);
     return comm;
   }
 

+ 2 - 5
packages/services/src/kernel/kernel.ts

@@ -302,12 +302,9 @@ namespace Kernel {
      *
      * @param id - The comm id.
      *
-     * @returns A promise that resolves with a comm instance.
-     *
-     * #### Notes
-     * If a promise to client-side comm already exists, it is returned.
+     * @returns A comm instance.
      */
-    connectToComm(targetName: string, commId?: string): Promise<Kernel.IComm>;
+    connectToComm(targetName: string, commId?: string): Kernel.IComm;
 
     /**
      * Register a comm target handler.