- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from samchon/features/stdio
Add `stdio` property on `WorkerConnector`
Showing
8 changed files
with
81 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,25 @@ | ||
import { WorkerConnector } from "../WorkerConnector"; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export interface IWorkerCompiler { | ||
compile(content: string): Promise<string>; | ||
remove(path: string): Promise<void>; | ||
execute(jsFile: string, argv: string[] | undefined): Promise<Worker>; | ||
execute( | ||
jsFile: string, | ||
options?: Partial<WorkerConnector.IConnectOptions>, | ||
): Promise<Worker>; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export namespace IWorkerCompiler { | ||
export type Creator = { | ||
new (jsFile: string, execArgv: string[] | undefined): IWorkerCompiler; | ||
new ( | ||
jsFile: string, | ||
options?: Partial<WorkerConnector.IConnectOptions>, | ||
): IWorkerCompiler; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { WorkerServer } from "tgrid"; | ||
|
||
import { IScientific } from "../../../../controllers/ICalculator"; | ||
|
||
class ScientificCalculator implements IScientific { | ||
public pow(x: number, y: number): number { | ||
console.log("pow", x, y); | ||
return Math.pow(x, y); | ||
} | ||
public sqrt(x: number): number { | ||
console.log("sqrt", x); | ||
return Math.sqrt(x); | ||
} | ||
public log(x: number, y: number): number { | ||
console.log("log", x, y); | ||
return Math.log(x) / Math.log(y); | ||
} | ||
} | ||
|
||
async function main(): Promise<void> { | ||
const server = new WorkerServer(); | ||
await server.open(new ScientificCalculator()); | ||
} | ||
main().catch((exp) => { | ||
console.log(exp); | ||
process.exit(-1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Driver, WorkerConnector } from "tgrid"; | ||
|
||
import { IScientific } from "../../../controllers/ICalculator"; | ||
|
||
export async function test_worker_stdio(): Promise<void> { | ||
const connector = new WorkerConnector(null, null, "process"); | ||
await connector.connect(`${__dirname}/internal/loud.js`, { | ||
stdio: "ignore", | ||
}); | ||
|
||
const driver: Driver<IScientific> = connector.getDriver<IScientific>(); | ||
await driver.pow(2, 4); | ||
await driver.sqrt(16); | ||
|
||
await connector.close(); | ||
} |