root / Assets / Plugins / UnityHTTP / ResponseCallbackDispatcher.cs @ 9:37719e88568d
History | View | Annotate | Download (1.3 kB)
1 | using UnityEngine; |
---|---|
2 | using System; |
3 | using System.Collections; |
4 | |
5 | namespace HTTP |
6 | { |
7 | public class ResponseCallbackDispatcher : MonoBehaviour |
8 | { |
9 | private static ResponseCallbackDispatcher singleton = null; |
10 | private static GameObject singletonGameObject = null; |
11 | private static object singletonLock = new object(); |
12 | |
13 | public static ResponseCallbackDispatcher Singleton { |
14 | get { |
15 | return singleton; |
16 | } |
17 | } |
18 | |
19 | public Queue requests = Queue.Synchronized( new Queue() ); |
20 | |
21 | public static void Init() |
22 | { |
23 | if ( singleton != null ) |
24 | { |
25 | return; |
26 | } |
27 | |
28 | lock( singletonLock ) |
29 | { |
30 | if ( singleton != null ) |
31 | { |
32 | return; |
33 | } |
34 | |
35 | singletonGameObject = new GameObject(); |
36 | singleton = singletonGameObject.AddComponent< ResponseCallbackDispatcher >(); |
37 | singletonGameObject.name = "HTTPResponseCallbackDispatcher"; |
38 | } |
39 | } |
40 | |
41 | public void Update() |
42 | { |
43 | while( requests.Count > 0 ) |
44 | { |
45 | HTTP.Request request = (Request)requests.Dequeue(); |
46 | request.completedCallback( request ); |
47 | } |
48 | } |
49 | } |
50 | } |