zrg
2024-08-16 18865d8bf24382e850e661dec6cca0e8b9dba6ae
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
 
namespace Taobao.Top.Link.Endpoints
{
    public class SendCallback
    {
        private EventWaitHandle _handle;
        private Exception _error;
        private IDictionary<string, object> _return;
 
        /// <summary>get which endpoint to send
        /// </summary>
        public EndpointProxy Target { get; private set; }
        /// <summary>get error in sending
        /// </summary>
        public Exception Error
        {
            get { return this._error; }
            internal set
            {
                this._error = value;
                this._handle.Set();
            }
        }
        /// <summary>get reply
        /// </summary>
        public IDictionary<string, object> Return
        {
            get { return this._return; }
            internal set
            {
                this._return = value;
                this._handle.Set();
            }
        }
 
        public SendCallback(EndpointProxy endpointProxy)
        {
            this.Target = endpointProxy;
            this._handle = new EventWaitHandle(false, EventResetMode.AutoReset);
        }
        /// <summary>wait until got return message
        /// </summary>
        /// <param name="timeout">timeout in milliseconds</param>
        public void WaitReturn(int timeout)
        {
            if (timeout > 0)
            {
                if (!this._handle.WaitOne(timeout, false))
                    throw new LinkException(Text.E_EXECUTE_TIMEOUT);
            }
            else
                this._handle.WaitOne();
        }
    }
}