MCPcopy Index your code
hub / github.com/apache/tvm / registerAsyncServerFunc

Method registerAsyncServerFunc

web/src/runtime.ts:1808–1829  ·  view source on GitHub ↗

* Register an asyncfunction to be global function in the server. * * @param name The name of the function. * @param func function to be registered. * @param override Whether overwrite function in existing registry. * * Note: The async function will only be used for serving remote

(
    name: string,
    func: Function,
    override = false
  )

Source from the content-addressed store, hash-verified

1806 * These functions contains explicit continuation
1807 */
1808 registerAsyncServerFunc(
1809 name: string,
1810 func: Function,
1811 override = false
1812 ): void {
1813 const asyncVariant = (...args: Array<any>): void => {
1814 const fargs = args.slice(0, args.length - 1);
1815 // need to keep it alive until callback is fulfilled.
1816 const callback = this.detachFromCurrentScope(args[args.length - 1] as PackedFunc);
1817 const promise: Promise<any> = func(...fargs);
1818 const onFulfilled = (rv: any) => {
1819 callback(this.scalar(AsyncCallbackCode.kReturn, "int32"), rv);
1820 callback.dispose();
1821 };
1822 const onRejected = (reason: any) => {
1823 callback(this.scalar(AsyncCallbackCode.kException, "int32"), reason.toString());
1824 callback.dispose();
1825 };
1826 promise.then(onFulfilled, onRejected);
1827 };
1828 this.registerFunc("__async." + name, asyncVariant, override);
1829 }
1830
1831 /**
1832 * Asynchronously load webgpu pipelines when possible.

Callers 2

initWebGPUMethod · 0.95

Calls 1

registerFuncMethod · 0.95

Tested by

no test coverage detected