tone 15.1.22 → 15.1.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -346,9 +346,9 @@ export class Context extends BaseContext {
346
346
  //--------------------------------------------
347
347
 
348
348
  /**
349
- * Maps a module name to promise of the addModule method
349
+ * A set of unsettled promises returned by the addModule method
350
350
  */
351
- private _workletPromise: null | Promise<void> = null;
351
+ private _workletPromises = new Set<Promise<void>>();
352
352
 
353
353
  /**
354
354
  * Create an audio worklet node from a name and options. The module
@@ -370,17 +370,19 @@ export class Context extends BaseContext {
370
370
  isDefined(this.rawContext.audioWorklet),
371
371
  "AudioWorkletNode is only available in a secure context (https or localhost)"
372
372
  );
373
- if (!this._workletPromise) {
374
- this._workletPromise = this.rawContext.audioWorklet.addModule(url);
375
- }
376
- await this._workletPromise;
373
+ const workletPromise = this.rawContext.audioWorklet.addModule(url);
374
+
375
+ this._workletPromises.add(workletPromise);
376
+ workletPromise.finally(() => this._workletPromises.delete(workletPromise));
377
+
378
+ return workletPromise;
377
379
  }
378
380
 
379
381
  /**
380
382
  * Returns a promise which resolves when all of the worklets have been loaded on this context
381
383
  */
382
384
  protected async workletsAreReady(): Promise<void> {
383
- (await this._workletPromise) ? this._workletPromise : Promise.resolve();
385
+ await Promise.all(this._workletPromises);
384
386
  }
385
387
 
386
388
  //---------------------------
@@ -59,7 +59,15 @@ export abstract class ToneAudioWorklet<
59
59
  this._dummyParam = this._dummyGain.gain;
60
60
 
61
61
  // Register the processor
62
- this.context.addAudioWorkletModule(blobUrl).then(() => {
62
+ let workletPromise = ToneAudioWorklet._workletPromises.get(this.context);
63
+
64
+ if (workletPromise === undefined) {
65
+ workletPromise = this.context.addAudioWorkletModule(blobUrl);
66
+
67
+ ToneAudioWorklet._workletPromises.set(this.context, workletPromise);
68
+ }
69
+
70
+ workletPromise.then(() => {
63
71
  // create the worklet when it's read
64
72
  if (!this.disposed) {
65
73
  this._worklet = this.context.createAudioWorkletNode(
@@ -73,6 +81,8 @@ export abstract class ToneAudioWorklet<
73
81
  });
74
82
  }
75
83
 
84
+ private static _workletPromises = new WeakMap<any, Promise<void>>();
85
+
76
86
  dispose(): this {
77
87
  super.dispose();
78
88
  this._dummyGain.disconnect();
package/Tone/version.ts CHANGED
@@ -1 +1 @@
1
- export const version: string = "15.1.22";
1
+ export const version: string = "15.1.23";