Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let res = await this.counter.proxy.AllHello1("Всем Привет");
- class CounterComponent {
- public currentCount: any;
- public dictionary = {};
- public proxy: any;
- constructor() { this.SetProxy(); }
- private GetPromise(name: PropertyKey,args)
- {
- let key = Guid.newGuid();
- let promise = new Promise((resolve, reject) => {
- let item = new Item(resolve, args, name);
- this.dictionary[key] = item;
- });
- return promise;
- }
- private SetProxy(): void {
- let self=this;
- this.proxy = new Proxy({}, {
- get: function(rcvr: any, name: PropertyKey)
- {
- // Для свойства нужно вернуть Promise
- if (name == "AllHello3")
- return self.GetPromise(name, []);
- // А для Метода нужно вернуть функцию создающую Promise
- return (...args) => {
- return self.GetPromise(name,args)
- };
- }
- });
- }
- public async CallMethodAsync() {
- this.currentCount = await this.proxy.AllHello("Всем Привет");
- }
- public setResult(): void {
- let key: string;
- for (let name in this.dictionary) {
- key = name;
- }
- let item = <Item>this.dictionary[key];
- delete this.dictionary[key];
- item.resolve(item.value);
- }
- }
- console.log('before async result ');
- let res = await this.counter.proxy.AllHello1("Всем Привет");
- console.log('Всем привет ' + res);
- res = await this.counter.proxy.AllHello2();
- console.log('func ' + res);
- res = await this.counter.proxy.AllHello3;
- console.log('property ' + res);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement