本文整理汇总了TypeScript中lib/classes/connection.Connection类的典型用法代码示例。如果您正苦于以下问题:TypeScript Connection类的具体用法?TypeScript Connection怎么用?TypeScript Connection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Connection类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: fullyStartupConnection
return fullyStartupConnection().then(() => {
port.postMessage.resetHistory();
const p = connection.sendMessage("bar_value");
const {id} = port.postMessage.getCall(0).args[0];
port.onMessage.dispatch({
id,
isResponse: true,
target: moduleName,
value: "baz_response",
});
return p;
}).then((response) => {
开发者ID:RequestPolicyContinued,项目名称:requestpolicy,代码行数:12,代码来源:test-connection.ts
示例2: describe
describe("connection", function() {
const sinon = require("sinon").sandbox.create();
const browser = createBrowserApi();
const moduleName = "my-module";
const targetName = "my-target";
let port;
let connection: Connection<any, any>;
beforeEach(() => {
port = createPort(sinon);
const log = new Log();
connection = new Connection(
moduleName,
log,
targetName,
() => Promise.resolve(port)
);
});
afterEach(() => {
browser.flush();
sinon.restore();
});
function startupUntilStartupMessageSent() {
const pStartupMessageSent = new Promise((resolve) => {
port.postMessage.onFirstCall().callsFake(resolve);
});
connection.startup();
return pStartupMessageSent;
}
function fullyStartupConnection() {
return startupUntilStartupMessageSent().then(() => {
port.onMessage.dispatch({
id: "startup",
isResponse: true,
target: moduleName,
value: "ready",
});
return;
});
}
it("first add message listener, then send message", function() {
return startupUntilStartupMessageSent().then(() => {
sinon.assert.callOrder(
port.onMessage.addListener,
port.postMessage
);
sinon.assert.calledWithMatch(port.postMessage, {
id: "startup",
isResponse: false,
target: targetName,
value: "ready",
});
return;
});
});
it("responds to startup message from target", function() {
return startupUntilStartupMessageSent().then(() => {
port.postMessage.reset();
const pResponseSent = new Promise((resolve) => {
port.postMessage.callsFake(resolve);
});
port.onMessage.dispatch({
id: "startup",
isResponse: false,
target: moduleName,
value: "ready",
});
return pResponseSent;
}).then(() => {
sinon.assert.calledOnce(port.postMessage);
sinon.assert.calledWithMatch(port.postMessage, {
id: "startup",
isResponse: true,
target: targetName,
value: "ready",
});
return;
});
});
it("is not ready before target startup", function() {
return startupUntilStartupMessageSent().then(() => {
assert.strictEqual(connection.isReady(), false);
return;
});
});
it("is ready after receiving startup response", function() {
return startupUntilStartupMessageSent().then(() => {
port.onMessage.dispatch({
id: "startup",
isResponse: true,
target: moduleName,
//.........这里部分代码省略.........
开发者ID:RequestPolicyContinued,项目名称:requestpolicy,代码行数:101,代码来源:test-connection.ts
示例3: startupUntilStartupMessageSent
function startupUntilStartupMessageSent() {
const pStartupMessageSent = new Promise((resolve) => {
port.postMessage.onFirstCall().callsFake(resolve);
});
connection.startup();
return pStartupMessageSent;
}
开发者ID:RequestPolicyContinued,项目名称:requestpolicy,代码行数:7,代码来源:test-connection.ts
示例4:
}).then(() => {
assert.strictEqual(connection.isReady(), true);
return;
});
开发者ID:RequestPolicyContinued,项目名称:requestpolicy,代码行数:4,代码来源:test-connection.ts
注:本文中的lib/classes/connection.Connection类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论