Advertisement
Guest User

Untitled

a guest
Jan 12th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. let res = await this.counter.proxy.AllHello1("Всем Привет");
  2.  
  3. class CounterComponent {
  4. public currentCount: any;
  5. public dictionary = {};
  6. public proxy: any;
  7. constructor() { this.SetProxy(); }
  8.  
  9. private GetPromise(name: PropertyKey,args)
  10. {
  11.  
  12. let key = Guid.newGuid();
  13. let promise = new Promise((resolve, reject) => {
  14. let item = new Item(resolve, args, name);
  15. this.dictionary[key] = item;
  16.  
  17. });
  18.  
  19.  
  20. return promise;
  21. }
  22. private SetProxy(): void {
  23.  
  24. let self=this;
  25. this.proxy = new Proxy({}, {
  26.  
  27. get: function(rcvr: any, name: PropertyKey)
  28. {
  29. // Для свойства нужно вернуть Promise
  30. if (name == "AllHello3")
  31. return self.GetPromise(name, []);
  32. // А для Метода нужно вернуть функцию создающую Promise
  33. return (...args) => {
  34. return self.GetPromise(name,args)
  35. };
  36. }
  37. });
  38. }
  39.  
  40. public async CallMethodAsync() {
  41. this.currentCount = await this.proxy.AllHello("Всем Привет");
  42. }
  43.  
  44. public setResult(): void {
  45.  
  46. let key: string;
  47. for (let name in this.dictionary) {
  48. key = name;
  49. }
  50.  
  51. let item = <Item>this.dictionary[key];
  52. delete this.dictionary[key];
  53. item.resolve(item.value);
  54. }
  55. }
  56.  
  57. console.log('before async result ');
  58. let res = await this.counter.proxy.AllHello1("Всем Привет");
  59. console.log('Всем привет ' + res);
  60. res = await this.counter.proxy.AllHello2();
  61. console.log('func ' + res);
  62. res = await this.counter.proxy.AllHello3;
  63. console.log('property ' + res);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement