mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
Donkey clear and reset now terminate when busy (#2225)
* Donkey clear and reset now terminate when busy
This commit is contained in:
committed by
GitHub
parent
b1c33b7f79
commit
c3517f7973
4
core/package-lock.json
generated
4
core/package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@pyscript/core",
|
||||
"version": "0.6.5",
|
||||
"version": "0.6.6",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@pyscript/core",
|
||||
"version": "0.6.5",
|
||||
"version": "0.6.6",
|
||||
"license": "APACHE-2.0",
|
||||
"dependencies": {
|
||||
"@ungap/with-resolvers": "^0.1.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pyscript/core",
|
||||
"version": "0.6.5",
|
||||
"version": "0.6.6",
|
||||
"type": "module",
|
||||
"description": "PyScript",
|
||||
"module": "./index.js",
|
||||
|
||||
@@ -73,13 +73,22 @@ const utils = async (options) => {
|
||||
export default async (options = {}) => {
|
||||
let farmer = await utils(options);
|
||||
let working = false;
|
||||
const kill = () => {
|
||||
if (farmer) {
|
||||
farmer.xworker.terminate();
|
||||
farmer.terminal.dispose();
|
||||
farmer = null;
|
||||
}
|
||||
working = false;
|
||||
};
|
||||
const reload = async () => {
|
||||
kill();
|
||||
farmer = await utils(options);
|
||||
};
|
||||
const asyncTask = (method) => async (code) => {
|
||||
// race condition ... a new task has been
|
||||
// assigned while the previous one didn't finish
|
||||
if (working) {
|
||||
kill();
|
||||
farmer = await utils(options);
|
||||
}
|
||||
if (working) await reload();
|
||||
working = true;
|
||||
try {
|
||||
return await farmer[method](dedent(code));
|
||||
@@ -89,20 +98,16 @@ export default async (options = {}) => {
|
||||
working = false;
|
||||
}
|
||||
};
|
||||
const kill = () => {
|
||||
if (farmer) {
|
||||
farmer.xworker.terminate();
|
||||
farmer.terminal.dispose();
|
||||
farmer = null;
|
||||
working = false;
|
||||
}
|
||||
const asyncMethod = (method) => async () => {
|
||||
if (working) await reload();
|
||||
else farmer?.terminal[method]();
|
||||
};
|
||||
return {
|
||||
process: asyncTask("process"),
|
||||
execute: asyncTask("execute"),
|
||||
evaluate: asyncTask("evaluate"),
|
||||
clear: () => farmer?.terminal.clear(),
|
||||
reset: () => farmer?.terminal.reset(),
|
||||
clear: asyncMethod("clear"),
|
||||
reset: asyncMethod("reset"),
|
||||
kill,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -12,13 +12,23 @@ const {
|
||||
kill,
|
||||
} = await donkey({ terminal: '#container' });
|
||||
|
||||
clearButton.onclick = clear;
|
||||
killButton.onclick = kill;
|
||||
clearButton.onclick = async () => {
|
||||
killButton.disabled = true;
|
||||
clearButton.disabled = true;
|
||||
await clear();
|
||||
runButton.disabled = false;
|
||||
};
|
||||
killButton.onclick = () => {
|
||||
killButton.disabled = true;
|
||||
clearButton.disabled = true;
|
||||
runButton.disabled = true;
|
||||
kill();
|
||||
};
|
||||
|
||||
runButton.disabled = false;
|
||||
runButton.onclick = async () => {
|
||||
killButton.disabled = false;
|
||||
clearButton.disabled = true;
|
||||
clearButton.disabled = false;
|
||||
runButton.disabled = true;
|
||||
// multiline code
|
||||
await execute(`
|
||||
@@ -29,6 +39,5 @@ runButton.onclick = async () => {
|
||||
const name = await evaluate('input("what is your name? ")');
|
||||
alert(`Hello ${name}`);
|
||||
killButton.disabled = true;
|
||||
clearButton.disabled = false;
|
||||
runButton.disabled = false;
|
||||
};
|
||||
|
||||
4
core/types/core.d.ts
vendored
4
core/types/core.d.ts
vendored
@@ -2,8 +2,8 @@ export function donkey(options: any): Promise<{
|
||||
process: (code: any) => Promise<any>;
|
||||
execute: (code: any) => Promise<any>;
|
||||
evaluate: (code: any) => Promise<any>;
|
||||
clear: () => any;
|
||||
reset: () => any;
|
||||
clear: () => Promise<void>;
|
||||
reset: () => Promise<void>;
|
||||
kill: () => void;
|
||||
}>;
|
||||
export function offline_interpreter(config: any): string;
|
||||
|
||||
4
core/types/plugins/donkey.d.ts
vendored
4
core/types/plugins/donkey.d.ts
vendored
@@ -2,8 +2,8 @@ declare function _default(options?: {}): Promise<{
|
||||
process: (code: any) => Promise<any>;
|
||||
execute: (code: any) => Promise<any>;
|
||||
evaluate: (code: any) => Promise<any>;
|
||||
clear: () => any;
|
||||
reset: () => any;
|
||||
clear: () => Promise<void>;
|
||||
reset: () => Promise<void>;
|
||||
kill: () => void;
|
||||
}>;
|
||||
export default _default;
|
||||
|
||||
Reference in New Issue
Block a user