Skip to content

Commit 7a23c7e

Browse files
committed
Rename SpawnedPHP to AcquiredPHP throughout codebase
The AcquiredPHP type better describes what the interface represents: a PHP instance that has been acquired from the instance manager and must be reaped when done. SpawnedPHP is now a backwards-compatible type alias exported from index.ts.
1 parent f6a916c commit 7a23c7e

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

packages/php-wasm/node/src/test/php-part-1.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
PHPProcessManager,
55
sandboxedSpawnHandlerFactory,
66
setPhpIniEntries,
7-
type SpawnedPHP,
7+
type AcquiredPHP,
88
SupportedPHPVersions,
99
} from '@php-wasm/universal';
1010
import { createSpawnHandler, phpVar } from '@php-wasm/util';
@@ -1829,7 +1829,7 @@ phpLoaderOptions.forEach((options) => {
18291829
describe('sandboxedSpawnHandlerFactory', () => {
18301830
const phpVersion = RecommendedPHPVersion;
18311831
let php: PHP;
1832-
let spawnedPhp: SpawnedPHP;
1832+
let spawnedPhp: AcquiredPHP;
18331833
let processManager: PHPProcessManager;
18341834
beforeEach(async () => {
18351835
processManager = new PHPProcessManager({

packages/php-wasm/node/src/test/php-part-2.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
PHPProcessManager,
66
sandboxedSpawnHandlerFactory,
77
setPhpIniEntries,
8-
type SpawnedPHP,
8+
type AcquiredPHP,
99
SupportedPHPVersions,
1010
} from '@php-wasm/universal';
1111
import { joinPaths } from '@php-wasm/util';
@@ -1159,7 +1159,7 @@ phpLoaderOptions.forEach((options) => {
11591159
describe('sandboxedSpawnHandlerFactory', () => {
11601160
const phpVersion = RecommendedPHPVersion;
11611161
let php: PHP;
1162-
let spawnedPhp: SpawnedPHP;
1162+
let spawnedPhp: AcquiredPHP;
11631163
let processManager: PHPProcessManager;
11641164
beforeEach(async () => {
11651165
processManager = new PHPProcessManager({

packages/php-wasm/universal/src/lib/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ export { HttpCookieStore } from './http-cookie-store';
2424
export type { IteratePhpFilesOptions as IterateFilesOptions } from './iterate-files';
2525
export { iteratePhpFiles as iterateFiles } from './iterate-files';
2626
export { writeFilesStreamToPhp } from './write-files-stream-to-php';
27-
export type { PHPInstanceManager, AcquiredPHP } from './php-instance-manager';
27+
export type {
28+
PHPInstanceManager,
29+
AcquiredPHP,
30+
/**
31+
* Backwards compatibility alias.
32+
*/
33+
AcquiredPHP as SpawnedPHP,
34+
} from './php-instance-manager';
2835
export { SinglePHPInstanceManager } from './single-php-instance-manager';
2936
export type { SinglePHPInstanceManagerOptions } from './single-php-instance-manager';
3037
export { PHPProcessManager } from './php-process-manager';
@@ -33,7 +40,6 @@ export type {
3340
PHPFactory,
3441
PHPFactoryOptions,
3542
ProcessManagerOptions,
36-
SpawnedPHP,
3743
} from './php-process-manager';
3844

3945
export { PHPResponse, StreamedPHPResponse } from './php-response';

packages/php-wasm/universal/src/lib/php-process-manager.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ export type PHPFactoryOptions = {
88

99
export type PHPFactory = (options: PHPFactoryOptions) => Promise<PHP>;
1010

11-
/**
12-
* @deprecated Use AcquiredPHP from './php-instance-manager' instead.
13-
*/
14-
export type SpawnedPHP = AcquiredPHP;
15-
1611
export interface ProcessManagerOptions {
1712
/**
1813
* The maximum number of PHP instances that can exist at
@@ -74,14 +69,14 @@ export class MaxPhpInstancesError extends Error {
7469
*/
7570
export class PHPProcessManager implements PHPInstanceManager {
7671
private primaryPhp?: PHP;
77-
private primaryPhpPromise?: Promise<SpawnedPHP>;
72+
private primaryPhpPromise?: Promise<AcquiredPHP>;
7873
private primaryIdle = true;
79-
private nextInstance: Promise<SpawnedPHP> | null = null;
74+
private nextInstance: Promise<AcquiredPHP> | null = null;
8075
/**
8176
* All spawned PHP instances, including the primary PHP instance.
8277
* Used for bookkeeping and reaping all instances on dispose.
8378
*/
84-
private allInstances: Promise<SpawnedPHP>[] = [];
79+
private allInstances: Promise<AcquiredPHP>[] = [];
8580
private phpFactory?: PHPFactory;
8681
private maxPhpInstances: number;
8782
private semaphore: Semaphore;
@@ -148,7 +143,7 @@ export class PHPProcessManager implements PHPInstanceManager {
148143
considerPrimary = false,
149144
}: {
150145
considerPrimary?: boolean;
151-
} = {}): Promise<SpawnedPHP> {
146+
} = {}): Promise<AcquiredPHP> {
152147
/**
153148
* First and foremost, make sure we have the primary PHP instance in place.
154149
* We may not actually acquire it. We just need it to exist.
@@ -179,7 +174,7 @@ export class PHPProcessManager implements PHPInstanceManager {
179174
* budget left to optimistically start spawning the next
180175
* instance.
181176
*/
182-
const spawnedPhp =
177+
const AcquiredPHP =
183178
this.nextInstance || this.spawn({ isPrimary: false });
184179

185180
/**
@@ -192,7 +187,7 @@ export class PHPProcessManager implements PHPInstanceManager {
192187
} else {
193188
this.nextInstance = null;
194189
}
195-
return await spawnedPhp;
190+
return await AcquiredPHP;
196191
}
197192

198193
/**
@@ -201,7 +196,7 @@ export class PHPProcessManager implements PHPInstanceManager {
201196
* add the spawn promise to the allInstances array without waiting
202197
* for PHP to spawn.
203198
*/
204-
private spawn(factoryArgs: PHPFactoryOptions): Promise<SpawnedPHP> {
199+
private spawn(factoryArgs: PHPFactoryOptions): Promise<AcquiredPHP> {
205200
if (factoryArgs.isPrimary && this.allInstances.length > 0) {
206201
throw new Error(
207202
'Requested spawning a primary PHP instance when another primary instance already started spawning.'
@@ -231,7 +226,9 @@ export class PHPProcessManager implements PHPInstanceManager {
231226
/**
232227
* Actually acquires the lock and spawns a new PHP instance.
233228
*/
234-
private async doSpawn(factoryArgs: PHPFactoryOptions): Promise<SpawnedPHP> {
229+
private async doSpawn(
230+
factoryArgs: PHPFactoryOptions
231+
): Promise<AcquiredPHP> {
235232
let release: () => void;
236233
try {
237234
release = await this.semaphore.acquire();

0 commit comments

Comments
 (0)