當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Duplex.end方法代碼示例

本文整理匯總了TypeScript中stream.Duplex.end方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Duplex.end方法的具體用法?TypeScript Duplex.end怎麽用?TypeScript Duplex.end使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在stream.Duplex的用法示例。


在下文中一共展示了Duplex.end方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1:

 const invocationCallback = (errorValue, successValue) => {
     connection.end(JSON.stringify({
         result: successValue,
         errorMessage: errorValue && (errorValue.message || errorValue),
         errorDetails: errorValue && (errorValue.stack || null)
     }));
 };
開發者ID:Niaro,項目名稱:JavaScriptServices,代碼行數:7,代碼來源:SocketNodeInstanceEntryPoint.ts

示例2: Error

            const invocationCallback = (errorValue, successValue) => {
                if (hasInvokedCallback) {
                    throw new Error('Cannot supply more than one result. The callback has already been invoked,'
                        + ' or the result stream has already been accessed');
                }

                hasInvokedCallback = true;
                connection.end(JSON.stringify({
                    result: successValue,
                    errorMessage: errorValue && (errorValue.message || errorValue),
                    errorDetails: errorValue && (errorValue.stack || null)
                }));
            };
開發者ID:chris-herring,項目名稱:JavaScriptServices,代碼行數:13,代碼來源:SocketNodeInstanceEntryPoint.ts

示例3: dynamicRequire

    readline.createInterface(connection, null).on('line', line => {
        try {
            // Get a reference to the function to invoke
            const invocation = JSON.parse(line) as RpcInvocation;
            const invokedModule = dynamicRequire(path.resolve(process.cwd(), invocation.moduleName));
            const invokedFunction = invocation.exportedFunctionName ? invokedModule[invocation.exportedFunctionName] : invokedModule;

            // Prepare a callback for accepting non-streamed JSON responses
            let hasInvokedCallback = false;
            const invocationCallback = (errorValue, successValue) => {
                if (hasInvokedCallback) {
                    throw new Error('Cannot supply more than one result. The callback has already been invoked,'
                        + ' or the result stream has already been accessed');
                }

                hasInvokedCallback = true;
                connection.end(JSON.stringify({
                    result: successValue,
                    errorMessage: errorValue && (errorValue.message || errorValue),
                    errorDetails: errorValue && (errorValue.stack || null)
                }));
            };

            // Also support streamed binary responses
            Object.defineProperty(invocationCallback, 'stream', {
                enumerable: true,
                get: (): Duplex => {
                    hasInvokedCallback = true;
                    return connection;
                }
            });

            // Actually invoke it, passing through any supplied args
            invokedFunction.apply(null, [invocationCallback].concat(invocation.args));
        } catch (ex) {
            connection.end(JSON.stringify({
                errorMessage: ex.message,
                errorDetails: ex.stack
            }));
        }
    });
開發者ID:chris-herring,項目名稱:JavaScriptServices,代碼行數:41,代碼來源:SocketNodeInstanceEntryPoint.ts

示例4: dynamicRequire

    readline.createInterface(connection, null).on('line', line => {
        try {
            // Get a reference to the function to invoke
            const invocation = JSON.parse(line) as RpcInvocation;
            const invokedModule = dynamicRequire(path.resolve(process.cwd(), invocation.moduleName));
            const invokedFunction = invocation.exportedFunctionName ? invokedModule[invocation.exportedFunctionName] : invokedModule;

            // Actually invoke it, passing the callback followed by any supplied args
            const invocationCallback = (errorValue, successValue) => {
                connection.end(JSON.stringify({
                    result: successValue,
                    errorMessage: errorValue && (errorValue.message || errorValue),
                    errorDetails: errorValue && (errorValue.stack || null)
                }));
            };
            invokedFunction.apply(null, [invocationCallback].concat(invocation.args));
        } catch (ex) {
            connection.end(JSON.stringify({
                errorMessage: ex.message,
                errorDetails: ex.stack
            }));
        }
    });
開發者ID:Niaro,項目名稱:JavaScriptServices,代碼行數:23,代碼來源:SocketNodeInstanceEntryPoint.ts


注:本文中的stream.Duplex.end方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。