本文整理汇总了TypeScript中worker-rpc.RpcProvider类的典型用法代码示例。如果您正苦于以下问题:TypeScript RpcProvider类的具体用法?TypeScript RpcProvider怎么用?TypeScript RpcProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RpcProvider类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: RpcProvider
import { RpcProvider } from "worker-rpc";
import * as jsonMap from "json-source-map";
const rpcProvider = new RpcProvider((message: any, transfer: any) => postMessage(message, transfer));
onmessage = e => rpcProvider.dispatch(e.data);
rpcProvider.registerRpcHandler("generateSourceMap", ({ obj }: any) => jsonMap.stringify(obj, null, 2));
示例2: postMessage
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
declare function postMessage(message: any, transfer?: any): void;
import { RpcProviderInterface, RpcProvider } from 'worker-rpc';
let rpcProvider: RpcProvider = null,
port: MessagePort = null,
portPending: MessagePort = null;
function send(message: any, transfer?: any): void {
if (port) {
port.postMessage(message, transfer);
} else {
postMessage(message, transfer);
}
if (portPending) {
port = portPending;
port.onmessage = (e: MessageEvent) => rpcProvider.dispatch(e.data);
}
示例3:
onmessage = e => rpcProvider.dispatch(e.data);
示例4:
onmessage = (e: MessageEvent) => port || rpcProvider.dispatch(e.data);
示例5:
onmessage = messageEvent => rpcProvider.dispatch(messageEvent.data);