Skip to content

Commit

Permalink
feat: add CHECK_CAPABILITY method to target.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Sma1lboy committed Nov 26, 2024
1 parent eba1962 commit adebb26
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions clients/tabby-threads/source/targets/target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const TERMINATE = 2;
const RELEASE = 3;
const FUNCTION_APPLY = 5;
const FUNCTION_RESULT = 6;
const CHECK_CAPABILITY = 7;

interface MessageMap {
[CALL]: [string, string | number, any];
Expand All @@ -76,6 +77,7 @@ interface MessageMap {
[RELEASE]: [string];
[FUNCTION_APPLY]: [string, string, any];
[FUNCTION_RESULT]: [string, Error?, any?];
[CHECK_CAPABILITY]: [string, string];
}

type MessageData = {
Expand Down Expand Up @@ -325,6 +327,12 @@ export function createThread<

break;
}
case CHECK_CAPABILITY: {
const [id, methodToCheck] = data[1];
const hasMethod = activeApi.has(methodToCheck);
send(RESULT, [id, undefined, encoder.encode(hasMethod, encoderApi)[0]]);
break;
}
}
}

Expand All @@ -341,6 +349,16 @@ export function createThread<
);
}

// hasCapability is a special method that checks if a method is exposed on the other thread
if (property === "hasCapability") {
const methodToCheck = args[0];
const id = uuid();
const done = waitForResult(id);
send(CHECK_CAPABILITY, [id, methodToCheck]);
return done;
}

//normal call
const id = uuid();
const done = waitForResult(id);
const [encoded, transferables] = encoder.encode(args, encoderApi);
Expand Down

0 comments on commit adebb26

Please sign in to comment.