import { getRemoteOrThrow , IS_SERVER , waitForRemote } from "../internal" ; export default class ClientFunction < CallArgs extends ReadonlyArray < unknown > , ServerReturnType = unknown > { private instance : RemoteFunction ; constructor ( name ) { this . instance = getRemoteOrThrow ( "RemoteFunction" , name ) ; assert ( ! IS_SERVER , "Cannot create a Net.ClientFunction on the Server!" ) ; } public static Wait < CallArgs extends ReadonlyArray < unknown > = Array < unknown > , ServerReturnType = unknown > ( name ) { return Promise . defer < ClientFunction < CallArgs , ServerReturnType > > ( async ( resolve ) => { await waitForRemote ( "RemoteFunction" , name , 60 ) ; resolve ( new ClientFunction ( name ) ) ; } ) ; } param args public CallServer ( ... args ) { return this . instance . InvokeServer ( ... args ) ; } param args public async CallServerAsync ( ... args ) { return Promise . defer < ServerReturnType > ( ( resolve ) => { const result = this . instance . InvokeServer ( ... args ) as ServerReturnType ; resolve ( result ) ; } ) ; } }