本文整理汇总了TypeScript中eventemitter2.EventEmitter2类的典型用法代码示例。如果您正苦于以下问题:TypeScript EventEmitter2类的具体用法?TypeScript EventEmitter2怎么用?TypeScript EventEmitter2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EventEmitter2类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: addEventListener
export function addEventListener(name, fn) {
emitter.addListener(name, fn)
}
开发者ID:dianpeng,项目名称:fly,代码行数:3,代码来源:events.ts
示例2: fireFetchEvent
export function fireFetchEvent(url, req, body, callback) {
logger.debug("handling request event")
const selfCleaningCallback = (...args) => {
callback.apply(null, args)
try {
callback.release()
} catch (e) {
// ignore
}
if (body) {
try {
body.release()
} catch (e) {
// ignore
}
}
}
const fetchEvent = new FetchEvent(
"fetch",
{
request: new Request(
url,
Object.assign(req, {
body: (body && refToStream(body)) || null
})
)
},
async function fetchEventCallback(err, res) {
logger.debug("request event callback called", typeof err, typeof res, res instanceof Response)
if (err) {
logger.error(err, err.stack)
return selfCleaningCallback.apply(null, [err.toString()])
}
if (res.bodyUsed) {
return selfCleaningCallback.apply(null, [new Error("Body has already been used").toString()])
}
let b = null
if (isFlyStream(res.body)) {
b = res.body.flyStreamId
} else {
logger.debug("body source type:", res.bodySource.constructor.name)
if (typeof res.bodySource === "string") {
b = res.bodySource
} else {
b = bridge.wrapValue(await res.arrayBuffer())
}
}
logger.debug("got ourselves a body")
selfCleaningCallback.apply(undefined, [
null,
bridge.wrapValue({
headers: (res.headers && res.headers.toJSON()) || {},
status: res.status
}),
b
])
}
)
const fn = emitter.listeners("fetch").slice(-1)[0]
if (typeof fn !== "function") {
return selfCleaningCallback.apply(null, [
"No HTTP handler attached: make sure your app calls `fly.http.respondWith(...)."
])
}
if ((fn(fetchEvent) as any) instanceof Promise) {
return selfCleaningCallback.apply(null, ["'fetch' event handler function cannot return a promise."])
}
if (!fetchEvent.respondWithEntered) {
return selfCleaningCallback.apply(null, ["respondWith was not called for FetchEvent"])
}
}
开发者ID:dianpeng,项目名称:fly,代码行数:80,代码来源:events.ts
示例3: dispatchEvent
export function dispatchEvent(event) {
emitter.emit(event.type, event)
}
开发者ID:dianpeng,项目名称:fly,代码行数:3,代码来源:events.ts
示例4:
export const emitLog = (logData: any) => {
emitter.emit("log", logData);
};
开发者ID:concord-consortium,项目名称:lara,代码行数:3,代码来源:events.ts
注:本文中的eventemitter2.EventEmitter2类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论