How to use the tstl/exception.DomainError function in tstl

To help you get started, we’ve selected a few tstl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github samchon / tgrid / src / protocols / workers / SharedWorkerConnector.ts View on Github external
return new Promise((resolve, reject) => 
        {
            // TEST CONDITION
            if (this.port_ && this.state_ !== SharedWorkerConnector.State.CLOSED)
            {
                let err: Error;
                if (this.state_ === SharedWorkerConnector.State.CONNECTING)
                    err = new DomainError("On connecting.");
                else if (this.state_ === SharedWorkerConnector.State.OPEN)
                    err = new DomainError("Already connected.");
                else
                    err = new DomainError("Closing.");

                reject(err);
                return;
            }

            //----
            // CONNECTOR
            //----
            try
            {
                // PREPARE MEMBERS
                this.state_ = SharedWorkerConnector.State.CONNECTING;
                this.args_ = args;
                this.connector_ = new Pair(resolve, reject);

                // DO CONNECT
github samchon / tgrid / src / protocols / workers / WorkerServer.ts View on Github external
protected inspectReady(): Error | null
    {
        // NO ERROR
        if (this.state_ === WorkerServer.State.OPEN)
            return null;

        // ERROR, ONE OF THEM
        else if (this.state_ === WorkerServer.State.NONE)
            return new DomainError("Server is not opened yet.");
        else if (this.state_ === WorkerServer.State.OPENING)
            return new DomainError("Server is on opening; wait for a sec.");
        else if (this.state_ === WorkerServer.State.CLOSING)
            return new RuntimeError("Server is on closing.");

        // MAY NOT BE OCCURED
        else if (this.state_ === WorkerServer.State.CLOSED)
            return new RuntimeError("The server has been closed.");
        else
            return new RuntimeError("Unknown error, but not connected.");
    }
github samchon / tgrid / src / protocols / workers / SharedWorkerAcceptor.ts View on Github external
public async accept(provider: Provider | null = null): Promise
    {
        // TEST CONDITION
        if (this.state_ !== SharedWorkerAcceptor.State.NONE)
            throw new DomainError("You've already accepted (or rejected) the connection.");

        //----
        // ACCEPT CONNECTION
        //----
        this.state_ = SharedWorkerAcceptor.State.ACCEPTING;
        {
            // SET PROVIDER
            this.provider_ = provider;

            // PREPARE PORT
            this.port_.onmessage = this._Handle_message.bind(this);
            this.port_.start();

            // INFORM ACCEPTANCE
            this.port_.postMessage(SharedWorkerAcceptor.State.OPEN);
        }
github samchon / tgrid / src / protocols / workers / WorkerServer.ts View on Github external
public async open(provider: Provider | null = null): Promise
    {
        // TEST CONDITION
        if (is_node() === false)
        {
            if (self.document !== undefined)
                throw new DomainError("This is not Worker.");    
        }
        else if (global.process.send === undefined)
            throw new DomainError("This is not Child Process.");    
        else if (this.state_ !== WorkerServer.State.NONE)
            throw new DomainError("Server has opened yet.");
        
        // OPEN WORKER
        this.state_ = WorkerServer.State.OPENING;
        {
            this.provider_ = provider;
            g.onmessage = this._Handle_message.bind(this);
            g.postMessage(WorkerServer.State.OPEN);
        }
        this.state_ = WorkerServer.State.OPEN;
    }
github samchon / tgrid / src / protocols / web / WebAcceptor.ts View on Github external
return new Promise((resolve, reject) =>
        {
            // TEST CONDITION
            if (this.state_ !== WebAcceptor.State.NONE)
            {
                reject(new DomainError("You've already accepted (or rejected) the connection."));
                return;
            }

            // PREPARE HANDLER
            this.request_.on("requestRejected", async () =>
            {
                await this.destructor();
                resolve();
            });

            // DO REJECT
            this.state_ = WebAcceptor.State.REJECTING;
            this.request_.reject(status, reason, extraHeaders);
        });
    }
github samchon / tgrid / src / protocols / workers / WorkerServer.ts View on Github external
public async open(provider: Provider | null = null): Promise
    {
        // TEST CONDITION
        if (is_node() === false)
        {
            if (self.document !== undefined)
                throw new DomainError("This is not Worker.");    
        }
        else if (global.process.send === undefined)
            throw new DomainError("This is not Child Process.");    
        else if (this.state_ !== WorkerServer.State.NONE)
            throw new DomainError("Server has opened yet.");
        
        // OPEN WORKER
        this.state_ = WorkerServer.State.OPENING;
        {
            this.provider_ = provider;
            g.onmessage = this._Handle_message.bind(this);
            g.postMessage(WorkerServer.State.OPEN);
        }
        this.state_ = WorkerServer.State.OPEN;
    }
github samchon / tgrid / src / protocols / workers / WorkerConnector.ts View on Github external
private _Test_connection(): void
    {
        if (this.worker_ && this.state !== WorkerConnector.State.CLOSED)
        {
            if (this.state_ === WorkerConnector.State.CONNECTING)
                throw new DomainError("On connecting.");
            else if (this.state_ === WorkerConnector.State.OPEN)
                throw new DomainError("Already connected.");
            else
                throw new DomainError("Closing.");
        }
    }
github samchon / tgrid / src / protocols / workers / WorkerConnector.ts View on Github external
private _Test_connection(): void
    {
        if (this.worker_ && this.state !== WorkerConnector.State.CLOSED)
        {
            if (this.state_ === WorkerConnector.State.CONNECTING)
                throw new DomainError("On connecting.");
            else if (this.state_ === WorkerConnector.State.OPEN)
                throw new DomainError("Already connected.");
            else
                throw new DomainError("Closing.");
        }
    }