├── .gitignore ├── Promises ├── Assembly-CSharp-Editor-vs.csproj ├── Assembly-CSharp-Editor.csproj ├── Assembly-CSharp-vs.csproj ├── Assembly-CSharp.csproj ├── Assets │ ├── Example.meta │ ├── Example │ │ ├── AllProgressController.cs │ │ ├── AllProgressController.cs.meta │ │ ├── AllTogetherProgressController.cs │ │ ├── AllTogetherProgressController.cs.meta │ │ ├── AnyProgressController.cs │ │ ├── AnyProgressController.cs.meta │ │ ├── CollectProgressController.cs │ │ ├── CollectProgressController.cs.meta │ │ ├── DeferredProgressController.cs │ │ ├── DeferredProgressController.cs.meta │ │ ├── Example Scene.unity │ │ ├── Example Scene.unity.meta │ │ ├── ExampleInitContoller.cs │ │ ├── ExampleInitContoller.cs.meta │ │ ├── RescueProgressController.cs │ │ ├── RescueProgressController.cs.meta │ │ ├── TestCube.cs │ │ ├── TestCube.cs.meta │ │ ├── ThenCoroutineController.cs │ │ ├── ThenCoroutineController.cs.meta │ │ ├── ThenProgressController.cs │ │ └── ThenProgressController.cs.meta │ ├── Promises.meta │ ├── Promises │ │ ├── Coroutine.cs │ │ ├── Coroutine.cs.meta │ │ ├── CoroutineRunner.cs │ │ ├── CoroutineRunner.cs.meta │ │ ├── Deferred.cs │ │ ├── Deferred.cs.meta │ │ ├── MainThreadDispatcher.cs │ │ ├── MainThreadDispatcher.cs.meta │ │ ├── Promise.cs │ │ ├── Promise.cs.meta │ │ ├── PromiseFactory.cs │ │ ├── PromiseFactory.cs.meta │ │ ├── PromiseService.cs │ │ ├── PromiseService.cs.meta │ │ ├── PromiseState.cs │ │ └── PromiseState.cs.meta │ ├── Tests.meta │ └── Tests │ │ ├── Editor.meta │ │ ├── Editor │ │ ├── PromiseTests.cs │ │ └── PromiseTests.cs.meta │ │ ├── Integration Tests.meta │ │ └── Integration Tests │ │ ├── CoroutineGetsExceptionTest.cs │ │ ├── CoroutineGetsExceptionTest.cs.meta │ │ ├── CoroutineGetsLastYieldTest.cs │ │ ├── CoroutineGetsLastYieldTest.cs.meta │ │ ├── CoroutineGetsLastestValueBeforeYieldBreakTest.cs │ │ ├── CoroutineGetsLastestValueBeforeYieldBreakTest.cs.meta │ │ ├── CoroutineGetsNullTest.cs │ │ ├── CoroutineGetsNullTest.cs.meta │ │ ├── CoroutineGetsValueTest.cs │ │ ├── CoroutineGetsValueTest.cs.meta │ │ ├── CoroutinePromiseOnFailedCalledTest.cs │ │ ├── CoroutinePromiseOnFailedCalledTest.cs.meta │ │ ├── CoroutinePromiseOnFulfilledCalledTest.cs │ │ ├── CoroutinePromiseOnFulfilledCalledTest.cs.meta │ │ ├── CoroutinePromiseOnProgressedCalledTest.cs │ │ ├── CoroutinePromiseOnProgressedCalledTest.cs.meta │ │ ├── CoroutinePromiseRescueTest.cs │ │ ├── CoroutinePromiseRescueTest.cs.meta │ │ ├── CoroutinePromiseThenTest.cs │ │ ├── CoroutinePromiseThenTest.cs.meta │ │ ├── CoroutinePromiseWithArgsTest.cs │ │ ├── CoroutinePromiseWithArgsTest.cs.meta │ │ ├── PromiseCleansUpOnFailedTest.cs │ │ ├── PromiseCleansUpOnFailedTest.cs.meta │ │ ├── PromiseCleansUpOnFulfilledTest.cs │ │ ├── PromiseCleansUpOnFulfilledTest.cs.meta │ │ ├── PromiseOnFailedCalledTest.cs │ │ ├── PromiseOnFailedCalledTest.cs.meta │ │ ├── PromiseOnFulfilledCalledTest.cs │ │ ├── PromiseOnFulfilledCalledTest.cs.meta │ │ ├── PromiseOnProgressedCalledTest.cs │ │ ├── PromiseOnProgressedCalledTest.cs.meta │ │ ├── Tests.unity │ │ └── Tests.unity.meta ├── Library │ ├── AnnotationManager │ ├── AssetVersioning.db │ ├── BuildPlayer.prefs │ ├── BuildSettings.asset │ ├── EditorUserSettings.asset │ ├── LibraryFormatVersion.txt │ ├── MonoManager.asset │ └── ProjectSettings.asset ├── ProjectSettings │ ├── AudioManager.asset │ ├── DynamicsManager.asset │ ├── EditorBuildSettings.asset │ ├── EditorSettings.asset │ ├── GraphicsSettings.asset │ ├── InputManager.asset │ ├── NavMeshAreas.asset │ ├── NavMeshLayers.asset │ ├── NetworkManager.asset │ ├── Physics2DSettings.asset │ ├── ProjectSettings.asset │ ├── QualitySettings.asset │ ├── TagManager.asset │ └── TimeManager.asset ├── Promises-Unity-csharp.sln ├── Promises-Unity.sln ├── Promises-csharp.sln └── Promises.sln ├── Tests ├── Libraries │ ├── nspec │ │ ├── NSpec.dll │ │ ├── NSpec.dll.mdb │ │ ├── NSpecRunner.exe │ │ ├── NSpecRunner.exe.config │ │ └── NSpecRunner.exe.mdb │ └── nunit.framework.dll ├── Properties │ └── AssemblyInfo.cs ├── Tests.csproj ├── Tests.sln └── Tests │ ├── TestHelper.cs │ ├── describe_All.cs │ ├── describe_Any.cs │ ├── describe_Collect.cs │ ├── describe_Promise.cs │ ├── describe_Rescue.cs │ └── describe_Then.cs └── runTests.sh /.gitignore: -------------------------------------------------------------------------------- 1 | test-results 2 | bin 3 | *.userprefs 4 | 5 | ### Unity 6 | [Bb]uild 7 | [Cc]ache 8 | [Mm]etadata/ 9 | [Tt]emp/ 10 | [Oo]bj/ 11 | assetDatabase3 12 | expandedItems 13 | guidmapper 14 | FailedAssetImports.txt 15 | AssetImportState 16 | EditorUserBuildSettings.asset 17 | ScriptMapper 18 | AssetServerCacheV3 19 | InspectorExpandedItems.asset 20 | ScriptAssemblies/ 21 | CurrentLayout.dwlt 22 | *.unityproj 23 | Promises/Assets/UnityTestTools 24 | UnityTestTools.meta 25 | Promises/Library/ShaderCache 26 | shadercompiler-64bit* 27 | ShaderCache.db 28 | Promises/Library/GiCache 29 | -------------------------------------------------------------------------------- /Promises/Assembly-CSharp-Editor-vs.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 10.0.20506 7 | 2.0 8 | {DBE831DB-43D2-FC62-AE1C-4DE8C845CAA0} 9 | Library 10 | Properties 11 | 12 | Assembly-CSharp-Editor 13 | v3.5 14 | 512 15 | Assets 16 | 17 | 18 | true 19 | full 20 | false 21 | Temp\bin\Debug\ 22 | DEBUG;TRACE;UNITY_4_6_0;UNITY_4_6;UNITY_IPHONE;ENABLE_MICROPHONE;ENABLE_TEXTUREID_MAP;ENABLE_UNITYEVENTS;ENABLE_NEW_HIERARCHY ;ENABLE_AUDIO_FMOD;ENABLE_MONO;ENABLE_TERRAIN;ENABLE_SUBSTANCE;ENABLE_GENERICS;INCLUDE_WP8SUPPORT;ENABLE_WWW;ENABLE_IMAGEEFFECTS;UNITY_IPHONE_API;ENABLE_4_6_FEATURES;INCLUDE_WP_BLUE_SUPPORT;ENABLE_WEBCAM;INCLUDE_METROSUPPORT;ENABLE_NETWORK;ENABLE_PHYSICS;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_2D_PHYSICS;ENABLE_GAMECENTER;UNITY_IOS;ENABLE_SHADOWS;ENABLE_AUDIO;ENABLE_NAVMESH_CARVING;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;DEVELOPMENT_BUILD;ENABLE_PROFILER;UNITY_EDITOR;UNITY_EDITOR_OSX;UNITY_TEAM_LICENSE;UNITY_PRO_LICENSE;ENABLE_DUCK_TYPING 23 | prompt 24 | 4 25 | 0169 26 | 27 | 28 | pdbonly 29 | true 30 | Temp\bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 0169 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | /Applications/Unity 4.6/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll 43 | 44 | 45 | /Applications/Unity 4.6/Unity.app/Contents/Frameworks/Managed/UnityEditor.dll 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | /Applications/Unity 4.6/Unity.app/Contents/UnityExtensions/Unity/GUISystem/4.6.0/UnityEngine.UI.dll 103 | 104 | 105 | /Applications/Unity 4.6/Unity.app/Contents/UnityExtensions/Unity/GUISystem/4.6.0/Editor/UnityEditor.UI.dll 106 | 107 | 108 | /Users/sschmid/Work/sschmid/Dev/Unity/Libs/Promises/Promises/Assets/UnityTestTools/UnitTesting/Editor/NSubstitute/NSubstitute.dll 109 | 110 | 111 | /Users/sschmid/Work/sschmid/Dev/Unity/Libs/Promises/Promises/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/Mono.Cecil.dll 112 | 113 | 114 | /Users/sschmid/Work/sschmid/Dev/Unity/Libs/Promises/Promises/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/Mono.Cecil.Mdb.dll 115 | 116 | 117 | /Users/sschmid/Work/sschmid/Dev/Unity/Libs/Promises/Promises/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/nunit.core.dll 118 | 119 | 120 | /Users/sschmid/Work/sschmid/Dev/Unity/Libs/Promises/Promises/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/nunit.core.interfaces.dll 121 | 122 | 123 | /Users/sschmid/Work/sschmid/Dev/Unity/Libs/Promises/Promises/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/nunit.framework.dll 124 | 125 | 126 | /Applications/Unity 4.6/Unity.app/Contents/Frameworks/Managed/UnityEditor.Graphs.dll 127 | 128 | 129 | 130 | 131 | {078E3FFF-5273-27E8-12B5-6C83568FAB85} Assembly-CSharp-vs 132 | 133 | 134 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /Promises/Assembly-CSharp-Editor.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 10.0.20506 7 | 2.0 8 | {DBE831DB-43D2-FC62-AE1C-4DE8C845CAA0} 9 | Library 10 | Properties 11 | 12 | Assembly-CSharp-Editor 13 | v3.5 14 | 512 15 | Assets 16 | 17 | 18 | true 19 | full 20 | false 21 | Temp\bin\Debug\ 22 | DEBUG;TRACE;UNITY_4_6_0;UNITY_4_6;UNITY_IPHONE;ENABLE_MICROPHONE;ENABLE_TEXTUREID_MAP;ENABLE_UNITYEVENTS;ENABLE_NEW_HIERARCHY ;ENABLE_AUDIO_FMOD;ENABLE_MONO;ENABLE_TERRAIN;ENABLE_SUBSTANCE;ENABLE_GENERICS;INCLUDE_WP8SUPPORT;ENABLE_WWW;ENABLE_IMAGEEFFECTS;UNITY_IPHONE_API;ENABLE_4_6_FEATURES;INCLUDE_WP_BLUE_SUPPORT;ENABLE_WEBCAM;INCLUDE_METROSUPPORT;ENABLE_NETWORK;ENABLE_PHYSICS;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_2D_PHYSICS;ENABLE_GAMECENTER;UNITY_IOS;ENABLE_SHADOWS;ENABLE_AUDIO;ENABLE_NAVMESH_CARVING;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;DEVELOPMENT_BUILD;ENABLE_PROFILER;UNITY_EDITOR;UNITY_EDITOR_OSX;UNITY_TEAM_LICENSE;UNITY_PRO_LICENSE;ENABLE_DUCK_TYPING 23 | prompt 24 | 4 25 | 0169 26 | 27 | 28 | pdbonly 29 | true 30 | Temp\bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 0169 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | /Applications/Unity 4.6/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll 43 | 44 | 45 | /Applications/Unity 4.6/Unity.app/Contents/Frameworks/Managed/UnityEditor.dll 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | /Applications/Unity 4.6/Unity.app/Contents/UnityExtensions/Unity/GUISystem/4.6.0/UnityEngine.UI.dll 103 | 104 | 105 | /Applications/Unity 4.6/Unity.app/Contents/UnityExtensions/Unity/GUISystem/4.6.0/Editor/UnityEditor.UI.dll 106 | 107 | 108 | /Users/sschmid/Work/sschmid/Dev/Unity/Libs/Promises/Promises/Assets/UnityTestTools/UnitTesting/Editor/NSubstitute/NSubstitute.dll 109 | 110 | 111 | /Users/sschmid/Work/sschmid/Dev/Unity/Libs/Promises/Promises/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/Mono.Cecil.dll 112 | 113 | 114 | /Users/sschmid/Work/sschmid/Dev/Unity/Libs/Promises/Promises/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/Mono.Cecil.Mdb.dll 115 | 116 | 117 | /Users/sschmid/Work/sschmid/Dev/Unity/Libs/Promises/Promises/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/nunit.core.dll 118 | 119 | 120 | /Users/sschmid/Work/sschmid/Dev/Unity/Libs/Promises/Promises/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/nunit.core.interfaces.dll 121 | 122 | 123 | /Users/sschmid/Work/sschmid/Dev/Unity/Libs/Promises/Promises/Assets/UnityTestTools/UnitTesting/Editor/NUnit/Libs/nunit.framework.dll 124 | 125 | 126 | /Applications/Unity 4.6/Unity.app/Contents/Frameworks/Managed/UnityEditor.Graphs.dll 127 | 128 | 129 | 130 | 131 | {078E3FFF-5273-27E8-12B5-6C83568FAB85} Assembly-CSharp 132 | 133 | 134 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /Promises/Assembly-CSharp-vs.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 10.0.20506 7 | 2.0 8 | {078E3FFF-5273-27E8-12B5-6C83568FAB85} 9 | Library 10 | Properties 11 | 12 | Assembly-CSharp 13 | v3.5 14 | 512 15 | Assets 16 | 17 | 18 | true 19 | full 20 | false 21 | Temp\bin\Debug\ 22 | DEBUG;TRACE;UNITY_4_6_0;UNITY_4_6;UNITY_IPHONE;ENABLE_MICROPHONE;ENABLE_TEXTUREID_MAP;ENABLE_UNITYEVENTS;ENABLE_NEW_HIERARCHY ;ENABLE_AUDIO_FMOD;ENABLE_MONO;ENABLE_TERRAIN;ENABLE_SUBSTANCE;ENABLE_GENERICS;INCLUDE_WP8SUPPORT;ENABLE_WWW;ENABLE_IMAGEEFFECTS;UNITY_IPHONE_API;ENABLE_4_6_FEATURES;INCLUDE_WP_BLUE_SUPPORT;ENABLE_WEBCAM;INCLUDE_METROSUPPORT;ENABLE_NETWORK;ENABLE_PHYSICS;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_2D_PHYSICS;ENABLE_GAMECENTER;UNITY_IOS;ENABLE_SHADOWS;ENABLE_AUDIO;ENABLE_NAVMESH_CARVING;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;DEVELOPMENT_BUILD;ENABLE_PROFILER;UNITY_EDITOR;UNITY_EDITOR_OSX;UNITY_TEAM_LICENSE;UNITY_PRO_LICENSE 23 | prompt 24 | 4 25 | 0169 26 | 27 | 28 | pdbonly 29 | true 30 | Temp\bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 0169 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | /Applications/Unity 4.6/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll 43 | 44 | 45 | /Applications/Unity 4.6/Unity.app/Contents/Frameworks/Managed/UnityEditor.dll 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | /Applications/Unity 4.6/Unity.app/Contents/UnityExtensions/Unity/GUISystem/4.6.0/UnityEngine.UI.dll 123 | 124 | 125 | 126 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /Promises/Assembly-CSharp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 10.0.20506 7 | 2.0 8 | {078E3FFF-5273-27E8-12B5-6C83568FAB85} 9 | Library 10 | Properties 11 | 12 | Assembly-CSharp 13 | v3.5 14 | 512 15 | Assets 16 | 17 | 18 | true 19 | full 20 | false 21 | Temp\bin\Debug\ 22 | DEBUG;TRACE;UNITY_4_6_0;UNITY_4_6;UNITY_IPHONE;ENABLE_MICROPHONE;ENABLE_TEXTUREID_MAP;ENABLE_UNITYEVENTS;ENABLE_NEW_HIERARCHY ;ENABLE_AUDIO_FMOD;ENABLE_MONO;ENABLE_TERRAIN;ENABLE_SUBSTANCE;ENABLE_GENERICS;INCLUDE_WP8SUPPORT;ENABLE_WWW;ENABLE_IMAGEEFFECTS;UNITY_IPHONE_API;ENABLE_4_6_FEATURES;INCLUDE_WP_BLUE_SUPPORT;ENABLE_WEBCAM;INCLUDE_METROSUPPORT;ENABLE_NETWORK;ENABLE_PHYSICS;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_2D_PHYSICS;ENABLE_GAMECENTER;UNITY_IOS;ENABLE_SHADOWS;ENABLE_AUDIO;ENABLE_NAVMESH_CARVING;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;DEVELOPMENT_BUILD;ENABLE_PROFILER;UNITY_EDITOR;UNITY_EDITOR_OSX;UNITY_TEAM_LICENSE;UNITY_PRO_LICENSE 23 | prompt 24 | 4 25 | 0169 26 | 27 | 28 | pdbonly 29 | true 30 | Temp\bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 0169 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | /Applications/Unity 4.6/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll 43 | 44 | 45 | /Applications/Unity 4.6/Unity.app/Contents/Frameworks/Managed/UnityEditor.dll 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | /Applications/Unity 4.6/Unity.app/Contents/UnityExtensions/Unity/GUISystem/4.6.0/UnityEngine.UI.dll 123 | 124 | 125 | 126 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /Promises/Assets/Example.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5e4d622ffe00a4592a4cf52796c068d0 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Promises/Assets/Example/AllProgressController.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using Promises; 3 | using System.Threading; 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | public class AllProgressController : MonoBehaviour { 8 | void Start() { 9 | transform.localScale = Vector3.zero; 10 | GetAllPromise().QueueOnMainThread( 11 | result => new GameObject("All done"), 12 | null, 13 | progress => transform.localScale = new Vector3(progress * 10, 1f, 1f) 14 | ); 15 | } 16 | 17 | public static Promise GetAllPromise() { 18 | var promises = new List>(); 19 | for (int i = 0; i < 10; i++) { 20 | var localIndex = i + 1; 21 | promises.Add(Promise.WithAction(() => { 22 | Thread.Sleep(localIndex * 500); 23 | return new object(); 24 | })); 25 | } 26 | return Promise.All(promises.ToArray()); 27 | } 28 | 29 | int sleepAction(int result) { 30 | Thread.Sleep(500); 31 | throw new Exception(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Promises/Assets/Example/AllProgressController.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3c15ba485d78843ff88e66507ac9ddb4 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Example/AllTogetherProgressController.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using Promises; 3 | using System.Threading; 4 | using System; 5 | 6 | public class AllTogetherProgressController : MonoBehaviour { 7 | void Start() { 8 | transform.localScale = Vector3.zero; 9 | getAllTogether().QueueOnMainThread( 10 | result => new GameObject("All together done"), 11 | null, 12 | progress => transform.localScale = new Vector3(progress * 10, 1f, 1f) 13 | ); 14 | } 15 | 16 | Promise getAllTogether() { 17 | var all = AllProgressController.GetAllPromise().Wrap(); 18 | var any = AnyProgressController.GetAnyPromise().Wrap(); 19 | var collect = CollectProgressController.GetCollectPromise().Wrap(); 20 | var deferred = DeferredProgressController.GetDeferred().Wrap(); 21 | var rescue = RescueProgressController.GetRescuePromise().Wrap(); 22 | var then = ThenProgressController.GetTenWithThen().Wrap(); 23 | var thenCoroutine = ThenCoroutineController.GetTenWithThenCoroutine().Wrap(); 24 | return Promise.Collect(all, any, collect, deferred, rescue, then, thenCoroutine); 25 | } 26 | 27 | int sleepAction(int result) { 28 | Thread.Sleep(500); 29 | throw new Exception(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Promises/Assets/Example/AllTogetherProgressController.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1bee4b578e7c44fbb8e534bbc44860a3 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Example/AnyProgressController.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using Promises; 3 | using System.Threading; 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | public class AnyProgressController : MonoBehaviour { 8 | void Start() { 9 | transform.localScale = Vector3.zero; 10 | GetAnyPromise().QueueOnMainThread( 11 | result => new GameObject("Any done"), 12 | null, 13 | progress => transform.localScale = new Vector3(progress * 10, 1f, 1f) 14 | ); 15 | } 16 | 17 | public static Promise GetAnyPromise() { 18 | var promises = new List>(); 19 | for (int i = 0; i < 10; i++) { 20 | var localIndex = i + 1; 21 | promises.Add(Promise.WithAction(() => { 22 | Thread.Sleep(localIndex * 500); 23 | return 0; 24 | })); 25 | } 26 | return Promise.Any(promises.ToArray()); 27 | } 28 | 29 | int sleepAction(int result) { 30 | Thread.Sleep(500); 31 | throw new Exception(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Promises/Assets/Example/AnyProgressController.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f0e2b6978b95d4979ab10c04eb395762 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Example/CollectProgressController.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using Promises; 3 | using System.Threading; 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | public class CollectProgressController : MonoBehaviour { 8 | void Start() { 9 | transform.localScale = Vector3.zero; 10 | GetCollectPromise().QueueOnMainThread( 11 | result => new GameObject("Collect done"), 12 | null, 13 | progress => transform.localScale = new Vector3(progress * 10, 1f, 1f) 14 | ); 15 | } 16 | 17 | public static Promise GetCollectPromise() { 18 | var promises = new List>(); 19 | for (int i = 0; i < 5; i++) { 20 | var localIndex = i + 1; 21 | promises.Add(Promise.WithAction(() => { 22 | Thread.Sleep(localIndex * 500); 23 | return new object(); 24 | })); 25 | } 26 | for (int i = 5; i < 10; i++) { 27 | var localIndex = i + 1; 28 | promises.Add(Promise.WithAction(() => { 29 | Thread.Sleep(localIndex * 500); 30 | throw new Exception(); 31 | })); 32 | } 33 | return Promise.Collect(promises.ToArray()); 34 | } 35 | 36 | int sleepAction(int result) { 37 | Thread.Sleep(500); 38 | throw new Exception(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Promises/Assets/Example/CollectProgressController.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b175c72ee24d04f5eb94a129b2045018 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Example/DeferredProgressController.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using Promises; 3 | using System; 4 | using System.Threading; 5 | 6 | public class DeferredProgressController : MonoBehaviour { 7 | void Start() { 8 | transform.localScale = Vector3.zero; 9 | GetDeferred().QueueOnMainThread( 10 | result => new GameObject("Deferred done"), 11 | null, 12 | progress => transform.localScale = new Vector3(progress * 10, 1f, 1f) 13 | ); 14 | } 15 | 16 | public static Promise GetDeferred() { 17 | return customProgressPromise(true).Then(customProgressPromise()).Then(customProgressPromise()).Then(customProgressPromise()); 18 | } 19 | 20 | static PromisecustomProgressPromise(bool autoStart = false) { 21 | var deferred = new Deferred(); 22 | deferred.action = () => { 23 | Thread.Sleep(500); 24 | var progress = 0f; 25 | while (progress < 1f) { 26 | progress += 0.01f; 27 | progress = Math.Min(1f, progress); 28 | deferred.Progress(progress); 29 | Thread.Sleep(7); 30 | } 31 | return 0; 32 | }; 33 | 34 | return autoStart ? deferred.RunAsync() : deferred.promise; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Promises/Assets/Example/DeferredProgressController.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f6d4fb6c56e3a4a5395c28f6d176e259 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Example/Example Scene.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschmid/Promises-CSharp/ffa339f53e7a4f32c7785523125b8bb429c193d6/Promises/Assets/Example/Example Scene.unity -------------------------------------------------------------------------------- /Promises/Assets/Example/Example Scene.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ecc625024c0b549cbbe43ecf88be3128 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Promises/Assets/Example/ExampleInitContoller.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using Promises; 3 | 4 | public class ExampleInitContoller : MonoBehaviour { 5 | 6 | void Awake() { 7 | MainThreadDispatcher.Init(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Promises/Assets/Example/ExampleInitContoller.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c10b0d5157a5147858aedb93e5146907 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: -100 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Example/RescueProgressController.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using Promises; 3 | using System.Threading; 4 | using System; 5 | 6 | public class RescueProgressController : MonoBehaviour { 7 | void Start() { 8 | transform.localScale = Vector3.zero; 9 | GetRescuePromise().QueueOnMainThread( 10 | result => new GameObject("Rescue done"), 11 | null, 12 | progress => transform.localScale = new Vector3(progress * 10, 1f, 1f) 13 | ); 14 | } 15 | 16 | public static Promise GetRescuePromise() { 17 | var promise = Promise.WithAction(() => { 18 | Thread.Sleep(500); 19 | throw new Exception(); 20 | }).Rescue(arg => 0); 21 | 22 | for (int i = 0; i < 9; i++) { 23 | promise = promise.Then(sleepAction).Rescue(arg => 0); 24 | } 25 | 26 | return promise; 27 | } 28 | 29 | static int sleepAction(int result) { 30 | Thread.Sleep(500); 31 | throw new Exception(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Promises/Assets/Example/RescueProgressController.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e73a2738ab70840e490d69efe2e3f31c 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Example/TestCube.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | public class TestCube : MonoBehaviour { 4 | 5 | void Start () { 6 | Application.targetFrameRate = 60; 7 | } 8 | 9 | void Update () { 10 | if (transform.position.y < -10) { 11 | transform.position = new Vector3(0, 10f, 0); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Promises/Assets/Example/TestCube.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 31a07e52e9392412fb0c7944d1335ad0 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Example/ThenCoroutineController.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using UnityEngine; 3 | using Promises; 4 | 5 | public class ThenCoroutineController : MonoBehaviour { 6 | void Start() { 7 | transform.localScale = Vector3.zero; 8 | var p = GetTenWithThenCoroutine(); 9 | p.OnFulfilled += result => new GameObject("Then Coroutine done"); 10 | p.OnProgressed += progress => transform.localScale = new Vector3(progress * 10, 1f, 1f); 11 | } 12 | 13 | public static Promise GetTenWithThenCoroutine() { 14 | var promise = Promise.WithCoroutine(() => coroutine(0)); 15 | 16 | for (int i = 0; i < 9; i++) { 17 | promise = promise.ThenCoroutine(coroutine); 18 | } 19 | 20 | return promise; 21 | } 22 | 23 | static IEnumerator coroutine(int startIndex) { 24 | var endIndex = startIndex + 10; 25 | while (startIndex != endIndex) { 26 | startIndex++; 27 | yield return new WaitForSeconds(0.06f); 28 | } 29 | 30 | yield return startIndex; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Promises/Assets/Example/ThenCoroutineController.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f1d77d74fd57e40e08a32c52bead9b6f 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Example/ThenProgressController.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using Promises; 3 | using System.Threading; 4 | 5 | public class ThenProgressController : MonoBehaviour { 6 | void Start() { 7 | transform.localScale = Vector3.zero; 8 | GetTenWithThen().QueueOnMainThread( 9 | result => new GameObject("Then done"), 10 | null, 11 | progress => transform.localScale = new Vector3(progress * 10, 1f, 1f) 12 | ); 13 | } 14 | 15 | public static Promise GetTenWithThen() { 16 | var promise = Promise.WithAction(() => { 17 | Thread.Sleep(500); 18 | return 0; 19 | }); 20 | 21 | for (int i = 0; i < 9; i++) { 22 | promise = promise.Then(sleepAction); 23 | } 24 | 25 | return promise; 26 | } 27 | 28 | static int sleepAction(int result) { 29 | Thread.Sleep(500); 30 | return 0; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Promises/Assets/Example/ThenProgressController.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 67d5d358d4d6f4e98ac8a766ed5c2ec0 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Promises.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d9ea27e4afcf64f468351c6e68062c11 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Promises/Assets/Promises/Coroutine.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using UnityEngine; 4 | 5 | namespace Promises { 6 | public class Coroutine { 7 | public T returnValue { 8 | get { 9 | if (_exception != null) { 10 | throw _exception; 11 | } 12 | return _returnValue; 13 | } 14 | } 15 | 16 | public Coroutine coroutine; 17 | 18 | T _returnValue; 19 | Exception _exception; 20 | 21 | public IEnumerator WrapRoutine(IEnumerator routine) { 22 | while (true) { 23 | try { 24 | if (!routine.MoveNext()) { 25 | _returnValue = (T)routine.Current; 26 | yield break; 27 | } 28 | } catch (Exception ex) { 29 | _exception = ex; 30 | yield break; 31 | } 32 | 33 | yield return routine.Current; 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Promises/Assets/Promises/Coroutine.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3369994e5d8ba4b5b99b89e091c0e696 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | assetBundleName: 10 | -------------------------------------------------------------------------------- /Promises/Assets/Promises/CoroutineRunner.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using UnityEngine; 4 | 5 | namespace Promises { 6 | public class CoroutineRunner : MonoBehaviour { 7 | static CoroutineRunner _coroutineRunner; 8 | 9 | public static Coroutine StartRoutine(IEnumerator coroutine, Action> onComplete = null) { 10 | if (_coroutineRunner == null) { 11 | _coroutineRunner = new GameObject("CoroutineRunner").AddComponent(); 12 | DontDestroyOnLoad(_coroutineRunner); 13 | } 14 | 15 | return _coroutineRunner.StartCoroutine(coroutine, onComplete); 16 | } 17 | 18 | public Coroutine StartCoroutine(IEnumerator coroutine, Action> onComplete = null) { 19 | Coroutine coroutineObject = new Coroutine(); 20 | coroutineObject.coroutine = StartCoroutine(coroutineObject.WrapRoutine(coroutine)); 21 | if (onComplete != null) { 22 | StartCoroutine(onCompleteCoroutine(coroutineObject, onComplete)); 23 | } 24 | 25 | return coroutineObject; 26 | } 27 | 28 | IEnumerator onCompleteCoroutine(Coroutine coroutine, Action> onComplete) { 29 | yield return coroutine.coroutine; 30 | onComplete(coroutine); 31 | } 32 | 33 | void OnDestroy() { 34 | _coroutineRunner = null; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Promises/Assets/Promises/CoroutineRunner.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 725be051798da454d98a69e1b5149a57 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | assetBundleName: 10 | -------------------------------------------------------------------------------- /Promises/Assets/Promises/Deferred.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Threading; 4 | 5 | namespace Promises { 6 | public class Deferred : Promise { 7 | public Promise promise { get { return this; } } 8 | 9 | public Func action; 10 | public Func coroutine; 11 | 12 | public Promise RunAsync() { 13 | if (coroutine == null) { 14 | runAction(); 15 | } else { 16 | runCoroutine(); 17 | } 18 | 19 | return promise; 20 | } 21 | 22 | void runAction() { 23 | ThreadPool.QueueUserWorkItem(state => { 24 | try { 25 | Fulfill(action()); 26 | } catch (Exception ex) { 27 | Fail(ex); 28 | } 29 | }); 30 | } 31 | 32 | void runCoroutine() { 33 | MainThreadDispatcher.Dispatch(() => CoroutineRunner.StartRoutine(coroutine(), c => { 34 | try { 35 | Fulfill(c.returnValue); 36 | } catch (Exception ex) { 37 | Fail(ex); 38 | } 39 | })); 40 | } 41 | 42 | public void Fulfill(T result) { 43 | transitionToFulfilled(result); 44 | } 45 | 46 | public void Fail(Exception ex) { 47 | transitionToFailed(ex); 48 | } 49 | 50 | public void Progress(float progress) { 51 | setProgress(progress); 52 | } 53 | } 54 | 55 | public class PromiseAnyException : Exception { 56 | public PromiseAnyException() : base("All promises did fail!") { 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Promises/Assets/Promises/Deferred.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3430a0658abff461f922862a152d1177 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Promises/MainThreadDispatcher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading; 4 | using UnityEngine; 5 | 6 | namespace Promises { 7 | 8 | public class MainThreadDispatcher : MonoBehaviour { 9 | 10 | public static bool isOnMainThread { get { return _mainThreadId == Thread.CurrentThread.ManagedThreadId; } } 11 | 12 | static bool _isInitialized; 13 | static int _mainThreadId; 14 | static List _actions; 15 | static MainThreadDispatcher _dispatcher; 16 | 17 | public static void Init() { 18 | if (!_isInitialized) { 19 | _dispatcher = new GameObject(typeof(MainThreadDispatcher).Name).AddComponent(); 20 | UnityEngine.Object.DontDestroyOnLoad(_dispatcher); 21 | _mainThreadId = Thread.CurrentThread.ManagedThreadId; 22 | _actions = new List(); 23 | _isInitialized = true; 24 | } 25 | } 26 | 27 | public static void Dispatch(Action action) { 28 | if (!_isInitialized) { 29 | throw new Exception("MainThreadDispatcher has to be initialized from the main thread first!"); 30 | } 31 | 32 | if (isOnMainThread) { 33 | action(); 34 | } else { 35 | lock (_actions) { 36 | _actions.Add(action); 37 | } 38 | } 39 | } 40 | 41 | void Update() { 42 | Action[] actions = null; 43 | lock (_actions) { 44 | if (_actions.Count > 0) { 45 | actions = _actions.ToArray(); 46 | _actions.Clear(); 47 | } 48 | } 49 | if (actions != null) { 50 | foreach (var action in actions) { 51 | action(); 52 | } 53 | } 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /Promises/Assets/Promises/MainThreadDispatcher.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3f632a790c2474430be1fa62121cc275 3 | timeCreated: 1433777188 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Promises/Assets/Promises/Promise.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | 4 | namespace Promises { 5 | public class Promise { 6 | public event Fulfilled OnFulfilled { 7 | add { addOnFulfilled(value); } 8 | remove { _onFulfilled -= value; } 9 | } 10 | 11 | public event Failed OnFailed { 12 | add { addOnFailed(value); } 13 | remove { _onFailed -= value; } 14 | } 15 | 16 | public event Progressed OnProgressed { 17 | add { addOnProgress(value); } 18 | remove { _onProgressed -= value; } 19 | } 20 | 21 | public delegate void Fulfilled(T result); 22 | public delegate void Failed(Exception error); 23 | public delegate void Progressed(float progress); 24 | 25 | public PromiseState state { get { return _state.state; } } 26 | public T result { get { return _state.result; } } 27 | public Exception error { get { return _state.error; } } 28 | public float progress { get { return _state.progress; } } 29 | 30 | event Fulfilled _onFulfilled; 31 | event Failed _onFailed; 32 | event Progressed _onProgressed; 33 | 34 | protected volatile State _state; 35 | readonly object _lock = new object(); 36 | 37 | int _depth = 1; 38 | float _bias = 0f; 39 | float _fraction = 1f; 40 | 41 | public Promise() { 42 | _state = State.CreateUnfulfilled(); 43 | } 44 | 45 | public Promise Await() { 46 | while (state == PromiseState.Unfulfilled || !_state.allDelegatesCalled); 47 | return this; 48 | } 49 | 50 | public Promise Then(Func action) { 51 | var deferred = new Deferred(); 52 | deferred.action = () => action(result); 53 | return Then(deferred.promise); 54 | } 55 | 56 | public Promise ThenCoroutine(Func coroutine) { 57 | var deferred = new Deferred(); 58 | deferred.coroutine = () => coroutine(result); 59 | return Then(deferred.promise); 60 | } 61 | 62 | public Promise Then(Promise promise) { 63 | var deferred = (Deferred)promise; 64 | deferred._depth = _depth + 1; 65 | deferred._fraction = 1f / deferred._depth; 66 | deferred._bias = (float)_depth / (float)deferred._depth * progress; 67 | deferred.Progress(0); 68 | 69 | // Unity workaround. For unknown reasons, Unity won't compile using OnFulfilled += ..., OnFailed += ... or OnProgressed += ... 70 | addOnFulfilled(result => deferred.RunAsync()); 71 | addOnFailed(deferred.Fail); 72 | addOnProgress(p => { 73 | deferred._bias = (float)_depth / (float)deferred._depth * p; 74 | deferred.Progress(0); 75 | }); 76 | return deferred.promise; 77 | } 78 | 79 | public Promise Rescue(Func action) { 80 | var deferred = createDeferredRescue(d => d.action = () => action(error)); 81 | return deferred.promise; 82 | } 83 | 84 | public Promise RescueCoroutine(Func coroutine) { 85 | var deferred = createDeferredRescue(d => d.coroutine = () => coroutine(error)); 86 | return deferred.promise; 87 | } 88 | 89 | Deferred createDeferredRescue(Action> setAction) { 90 | var deferred = new Deferred(); 91 | deferred._depth = _depth; 92 | deferred._fraction = 1f; 93 | deferred.Progress(progress); 94 | setAction(deferred); 95 | addOnFulfilled(deferred.Fulfill); 96 | addOnFailed(error => deferred.RunAsync()); 97 | addOnProgress(deferred.Progress); 98 | return deferred; 99 | } 100 | 101 | public Promise Wrap() { 102 | var deferred = new Deferred(); 103 | deferred._depth = _depth; 104 | deferred._fraction = 1f; 105 | deferred.Progress(progress); 106 | addOnFulfilled(result => deferred.Fulfill((TWrap)(object)result)); 107 | addOnFailed(deferred.Fail); 108 | addOnProgress(deferred.Progress); 109 | return deferred.promise; 110 | } 111 | 112 | public override string ToString() { 113 | if (state == PromiseState.Fulfilled) { 114 | return string.Format("[Promise<{0}>: state = {1}, result = {2}]", typeof(T).Name, state, result); 115 | } 116 | if (state == PromiseState.Failed) { 117 | return string.Format("[Promise<{0}>: state = {1}, progress = {2:0.###}, error = {3}]", typeof(T).Name, state, progress, error.Message); 118 | } 119 | 120 | return string.Format("[Promise<{0}>: state = {1}, progress = {2:0.###}]", typeof(T).Name, state, progress); 121 | } 122 | 123 | void addOnFulfilled(Fulfilled value) { 124 | lock (_lock) { 125 | if (state == PromiseState.Unfulfilled) { 126 | _onFulfilled += value; 127 | } else if (state == PromiseState.Fulfilled) { 128 | value(result); 129 | } 130 | } 131 | } 132 | 133 | void addOnFailed(Failed value) { 134 | lock (_lock) { 135 | if (state == PromiseState.Unfulfilled) { 136 | _onFailed += value; 137 | } else if (state == PromiseState.Failed) { 138 | value(error); 139 | } 140 | } 141 | } 142 | 143 | void addOnProgress(Progressed value) { 144 | lock (_lock) { 145 | if (progress < 1f) { 146 | _onProgressed += value; 147 | } else { 148 | value(progress); 149 | } 150 | } 151 | } 152 | 153 | protected void transitionToFulfilled(T result) { 154 | lock (_lock) { 155 | if (state == PromiseState.Unfulfilled) { 156 | var oldProgress = progress; 157 | _state = _state.SetFulfilled(result); 158 | if (progress != oldProgress) { 159 | if (_onProgressed != null) { 160 | _onProgressed(progress); 161 | } 162 | } 163 | if (_onFulfilled != null) { 164 | _onFulfilled(result); 165 | } 166 | } else { 167 | throw new Exception(string.Format("Invalid state transition from {0} to {1}", state, PromiseState.Fulfilled)); 168 | } 169 | } 170 | 171 | cleanup(); 172 | } 173 | 174 | protected void transitionToFailed(Exception error) { 175 | lock (_lock) { 176 | if (state == PromiseState.Unfulfilled) { 177 | _state = _state.SetFailed(error); 178 | if (_onFailed != null) { 179 | _onFailed(error); 180 | } 181 | } else { 182 | throw new Exception(string.Format("Invalid state transition from {0} to {1}", state, PromiseState.Failed)); 183 | } 184 | } 185 | 186 | cleanup(); 187 | } 188 | 189 | protected void setProgress(float p) { 190 | lock (_lock) { 191 | var newProgress = _bias + p * _fraction; 192 | if (newProgress != progress) { 193 | _state = _state.SetProgress(newProgress); 194 | if (_onProgressed != null) { 195 | _onProgressed(progress); 196 | } 197 | } 198 | } 199 | } 200 | 201 | void cleanup() { 202 | _onFulfilled = null; 203 | _onFailed = null; 204 | _onProgressed = null; 205 | _state = _state.SetAllDelegatesCalled(); 206 | } 207 | } 208 | } 209 | -------------------------------------------------------------------------------- /Promises/Assets/Promises/Promise.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dd7636ece1f804fef9bfab143f4652a4 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Promises/PromiseFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Threading; 4 | 5 | namespace Promises { 6 | public static class Promise { 7 | 8 | public static Promise WithAction(Func action) { 9 | var deferred = new Deferred(); 10 | deferred.action = action; 11 | return deferred.RunAsync(); 12 | } 13 | 14 | public static Promise WithCoroutine(Func coroutine) { 15 | var deferred = new Deferred(); 16 | deferred.coroutine = coroutine; 17 | return deferred.RunAsync(); 18 | } 19 | 20 | public static Promise All(params Promise[] promises) { 21 | var deferred = new Deferred(); 22 | var results = new T[promises.Length]; 23 | var done = 0; 24 | 25 | var initialProgress = 0f; 26 | foreach (var p in promises) { 27 | initialProgress += p.progress; 28 | } 29 | 30 | deferred.Progress(initialProgress / (float)promises.Length); 31 | 32 | for (int i = 0, promisesLength = promises.Length; i < promisesLength; i++) { 33 | var localIndex = i; 34 | var promise = promises[localIndex]; 35 | promise.OnFulfilled += result => { 36 | if (deferred.state == PromiseState.Unfulfilled) { 37 | results[localIndex] = result; 38 | Interlocked.Increment(ref done); 39 | if (done == promisesLength) { 40 | deferred.Fulfill(results); 41 | } 42 | } 43 | }; 44 | promise.OnFailed += error => { 45 | if (deferred.state == PromiseState.Unfulfilled) { 46 | deferred.Fail(error); 47 | } 48 | }; 49 | promise.OnProgressed += progress => { 50 | if (deferred.state == PromiseState.Unfulfilled) { 51 | var totalProgress = 0f; 52 | foreach (var p in promises) { 53 | totalProgress += p.progress; 54 | } 55 | deferred.Progress(totalProgress / (float)promisesLength); 56 | } 57 | }; 58 | } 59 | 60 | return deferred.promise; 61 | } 62 | 63 | public static Promise Any(params Promise[] promises) { 64 | var deferred = new Deferred(); 65 | var failed = 0; 66 | 67 | var initialProgress = 0f; 68 | foreach (var p in promises) { 69 | if (p.progress > initialProgress) { 70 | initialProgress = p.progress; 71 | } 72 | } 73 | deferred.Progress(initialProgress); 74 | 75 | for (int i = 0, promisesLength = promises.Length; i < promisesLength; i++) { 76 | var localIndex = i; 77 | var promise = promises[localIndex]; 78 | promise.OnFulfilled += result => { 79 | if (deferred.state == PromiseState.Unfulfilled) { 80 | deferred.Fulfill(result); 81 | } 82 | }; 83 | promise.OnFailed += error => { 84 | if (deferred.state == PromiseState.Unfulfilled) { 85 | Interlocked.Increment(ref failed); 86 | if (failed == promisesLength) { 87 | deferred.Fail(new PromiseAnyException()); 88 | } 89 | } 90 | }; 91 | promise.OnProgressed += progress => { 92 | if (deferred.state == PromiseState.Unfulfilled) { 93 | var maxProgress = 0f; 94 | foreach (var p in promises) { 95 | if (p.progress > maxProgress) { 96 | maxProgress = p.progress; 97 | } 98 | } 99 | deferred.Progress(maxProgress); 100 | } 101 | }; 102 | } 103 | 104 | return deferred.promise; 105 | } 106 | 107 | public static Promise Collect(params Promise[] promises) { 108 | var deferred = new Deferred(); 109 | var results = new object[promises.Length]; 110 | var done = 0; 111 | 112 | var initialProgress = 0f; 113 | foreach (var p in promises) { 114 | initialProgress += p.progress; 115 | } 116 | 117 | deferred.Progress(initialProgress / (float)promises.Length); 118 | 119 | for (int i = 0, promisesLength = promises.Length; i < promisesLength; i++) { 120 | var localIndex = i; 121 | var promise = promises[localIndex]; 122 | promise.OnFulfilled += result => { 123 | results[localIndex] = result; 124 | Interlocked.Increment(ref done); 125 | if (done == promisesLength) { 126 | deferred.Fulfill(results); 127 | } 128 | }; 129 | promise.OnFailed += error => { 130 | var totalProgress = 0f; 131 | foreach (var p in promises) { 132 | totalProgress += p.state == PromiseState.Failed ? 1f : p.progress; 133 | } 134 | deferred.Progress(totalProgress / (float)promisesLength); 135 | Interlocked.Increment(ref done); 136 | if (done == promisesLength) { 137 | deferred.Fulfill(results); 138 | } 139 | }; 140 | promise.OnProgressed += progress => { 141 | var totalProgress = 0f; 142 | foreach (var p in promises) { 143 | totalProgress += p.state == PromiseState.Failed ? 1f : p.progress; 144 | } 145 | deferred.Progress(totalProgress / (float)promisesLength); 146 | }; 147 | } 148 | 149 | return deferred.promise; 150 | } 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /Promises/Assets/Promises/PromiseFactory.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3f7b5a68419104cada6c8ea6a908bfce 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Promises/PromiseService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using Promises; 3 | using UnityEngine; 4 | 5 | namespace Promises { 6 | public static class PromiseExtensions { 7 | public static Promise QueueOnMainThread(this Promise promise, 8 | Promise.Fulfilled onFulfilled, 9 | Promise.Failed onFailed = null, 10 | Promise.Progressed onProgressed = null) { 11 | 12 | PromiseService.AddPromise(promise, onFulfilled, onFailed, onProgressed); 13 | return promise; 14 | } 15 | } 16 | 17 | public class PromiseService : MonoBehaviour { 18 | public int promises { get { return _promises; } } 19 | 20 | static PromiseService _service; 21 | int _promises; 22 | 23 | public static void AddPromise(Promise promise, 24 | Promise.Fulfilled onFulfilled = null, 25 | Promise.Failed onFailed = null, 26 | Promise.Progressed onProgressed = null) { 27 | 28 | Promise.Fulfilled fulfilledHandler = null; 29 | Promise.Failed failedHandler = null; 30 | Promise.Progressed progressedHandler = null; 31 | 32 | if (onFulfilled != null) { 33 | if (promise.state == PromiseState.Fulfilled) { 34 | onFulfilled(promise.result); 35 | } else { 36 | fulfilledHandler = onFulfilled; 37 | } 38 | } 39 | 40 | if (onFailed != null) { 41 | if (promise.state == PromiseState.Failed) { 42 | onFailed(promise.error); 43 | } else { 44 | failedHandler = onFailed; 45 | } 46 | } 47 | 48 | if (promise.state == PromiseState.Unfulfilled) { 49 | if (onProgressed != null) { 50 | progressedHandler = onProgressed; 51 | if (promise.progress > 0) { 52 | onProgressed(promise.progress); 53 | } 54 | } 55 | } 56 | 57 | if (fulfilledHandler != null || failedHandler != null || progressedHandler != null) { 58 | getService().addPromiseWithHandler(new PromiseWithHandler( 59 | promise, fulfilledHandler, 60 | failedHandler, progressedHandler 61 | )); 62 | } 63 | } 64 | 65 | static PromiseService getService() { 66 | if (_service == null) { 67 | _service = new GameObject("PromiseService").AddComponent(); 68 | DontDestroyOnLoad(_service); 69 | _service.updateName(); 70 | } 71 | 72 | return _service; 73 | } 74 | 75 | void addPromiseWithHandler(PromiseWithHandler promiseWithHandler) { 76 | _promises++; 77 | updateName(); 78 | StartCoroutine(update(promiseWithHandler)); 79 | } 80 | 81 | IEnumerator update(PromiseWithHandler p) { 82 | while (true) { 83 | if (p.onProgressed != null) { 84 | if (p.promise.progress != p.previousProgress) { 85 | p.previousProgress = p.promise.progress; 86 | p.onProgressed(p.promise.progress); 87 | } 88 | } 89 | 90 | if (p.promise.state == PromiseState.Fulfilled) { 91 | if (p.onFulfilled != null) { 92 | p.onFulfilled(p.promise.result); 93 | } 94 | _promises--; 95 | updateName(); 96 | yield break; 97 | } 98 | 99 | if (p.promise.state == PromiseState.Failed) { 100 | if (p.onFailed != null) { 101 | p.onFailed(p.promise.error); 102 | } 103 | _promises--; 104 | updateName(); 105 | yield break; 106 | } 107 | 108 | yield return new WaitForEndOfFrame(); 109 | } 110 | } 111 | 112 | void updateName() { 113 | name = "Promises (" + _promises + " pending)"; 114 | } 115 | 116 | void OnDestroy() { 117 | _service = null; 118 | } 119 | } 120 | 121 | class PromiseWithHandler { 122 | public float previousProgress; 123 | public Promise promise { get { return _promise; } } 124 | public Promise.Fulfilled onFulfilled { get { return _onFulfilled; } } 125 | public Promise.Failed onFailed { get { return _onFailed; } } 126 | public Promise.Progressed onProgressed { get { return _onProgressed; } } 127 | 128 | readonly Promise _promise; 129 | readonly Promise.Fulfilled _onFulfilled; 130 | readonly Promise.Failed _onFailed; 131 | readonly Promise.Progressed _onProgressed; 132 | 133 | public PromiseWithHandler(Promise promise, 134 | Promise.Fulfilled onFulfilled = null, 135 | Promise.Failed onFailed = null, 136 | Promise.Progressed onProgressed = null) { 137 | 138 | _promise = promise; 139 | _onFulfilled = onFulfilled; 140 | _onFailed = onFailed; 141 | _onProgressed = onProgressed; 142 | } 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /Promises/Assets/Promises/PromiseService.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2fe1aa364970b4d4bb7c734a56ff7be7 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Promises/PromiseState.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Promises { 4 | public enum PromiseState : byte { 5 | Unfulfilled, 6 | Failed, 7 | Fulfilled 8 | } 9 | 10 | public class State { 11 | public PromiseState state { get { return _state; } } 12 | public T result { get { return _result; } } 13 | public Exception error { get { return _error; } } 14 | public float progress { get { return _progress; } } 15 | public bool allDelegatesCalled { get { return _allDelegatesCalled; } } 16 | 17 | readonly PromiseState _state; 18 | readonly T _result; 19 | readonly Exception _error; 20 | readonly float _progress; 21 | readonly bool _allDelegatesCalled; 22 | 23 | State(PromiseState state, T result, Exception error, float progress, bool allDelegatesCalled) { 24 | _state = state; 25 | _result = result; 26 | _error = error; 27 | _progress = progress; 28 | _allDelegatesCalled = allDelegatesCalled; 29 | } 30 | 31 | public static State CreateUnfulfilled() { 32 | return new State(PromiseState.Unfulfilled, default(T), null, 0f, false); 33 | } 34 | 35 | public State SetFulfilled(T result) { 36 | return new State(PromiseState.Fulfilled, result, null, 1f, false); 37 | } 38 | 39 | public State SetFailed(Exception error) { 40 | return new State(PromiseState.Failed, _result, error, _progress, false); 41 | } 42 | 43 | public State SetProgress(float p) { 44 | return new State(_state, _result, _error, p, false); 45 | } 46 | 47 | public State SetAllDelegatesCalled() { 48 | return new State(_state, _result, _error, _progress, true); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Promises/Assets/Promises/PromiseState.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 53f466252519f43ae95013d3adece938 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Tests.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 519e5e2644a744dd6a981d7d5197d26d 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9f2ce5ef02a6e4045ab2c26ad282dea6 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Editor/PromiseTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading; 4 | using NUnit.Framework; 5 | using Promises; 6 | 7 | [TestFixture] 8 | class PromiseTests { 9 | 10 | void sleepShort() { 11 | Thread.Sleep(5); 12 | } 13 | 14 | void sleepLong() { 15 | Thread.Sleep(10); 16 | } 17 | 18 | [Test] 19 | public void QueueOnMainThread_returns_promise() { 20 | var p = Promise.WithAction(() => 42); 21 | Assert.AreSame(p, p.QueueOnMainThread(null)); 22 | } 23 | 24 | [Test] 25 | public void fulfilled_promise_calls_onFulfilled_immediately() { 26 | var p = Promise.WithAction(() => 42); 27 | sleepShort(); 28 | var result = 0; 29 | p.QueueOnMainThread(r => result = r); 30 | Assert.AreEqual(42, result); 31 | } 32 | 33 | [Test] 34 | public void handles_null_onFulfilled_hanlder() { 35 | var p = Promise.WithAction(() => 42); 36 | sleepShort(); 37 | p.QueueOnMainThread(null); 38 | } 39 | 40 | [Test] 41 | public void failed_promise_calls_onFailed_immediately() { 42 | var p = Promise.WithAction(() => { 43 | throw new Exception("42"); 44 | }); 45 | sleepShort(); 46 | var errorMsg = ""; 47 | p.QueueOnMainThread(null, error => errorMsg = error.Message); 48 | Assert.AreEqual("42", errorMsg); 49 | } 50 | 51 | [Test] 52 | public void handles_null_onFailed_hanlder() { 53 | var p = Promise.WithAction(() => { 54 | throw new Exception("42"); 55 | }); 56 | sleepShort(); 57 | p.QueueOnMainThread(null, null); 58 | } 59 | 60 | [Test] 61 | public void calls_onProgressed_immediately_when_greater_0() { 62 | var d = new Deferred(); 63 | d.Progress(0.42f); 64 | var progress = 0f; 65 | d.promise.QueueOnMainThread(null, null, p => { 66 | progress = p; 67 | }); 68 | Assert.AreEqual(0.42f, progress); 69 | } 70 | 71 | [Test] 72 | public void does_not_call_onProgressed_immediately_when_0() { 73 | var d = new Deferred(); 74 | d.Progress(0f); 75 | var progressCalled = false; 76 | d.promise.QueueOnMainThread(null, null, p => { 77 | progressCalled = true; 78 | }); 79 | Assert.IsFalse(progressCalled); 80 | } 81 | 82 | [Test] 83 | public void handles_null_onProgressed_hanlder() { 84 | var d = new Deferred(); 85 | d.Progress(0.42f); 86 | d.QueueOnMainThread(null, null, null); 87 | } 88 | 89 | [Test] 90 | public void then_coroutine_after_action() { 91 | MainThreadDispatcher.Init(); 92 | var p = Promise 93 | .WithAction(() => 42) 94 | .ThenCoroutine(coroutine); 95 | 96 | p.OnFulfilled += result => Assert.AreEqual(42 * 42, result); 97 | p.OnFailed += error => Assert.Fail(); 98 | } 99 | 100 | System.Collections.IEnumerator coroutine(int result) { 101 | yield return 42 * result; 102 | } 103 | } 104 | 105 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Editor/PromiseTests.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 959a669688f154725aa4a3c37f8ccf7f 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e777c0098d98a49258c3fb7285e7a6a3 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/CoroutineGetsExceptionTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using UnityEngine; 4 | using Promises; 5 | 6 | public class CoroutineGetsExceptionTest : MonoBehaviour { 7 | 8 | public Exception exception; 9 | 10 | void Start() { 11 | CoroutineRunner.StartRoutine(coroutine(), onComplete); 12 | } 13 | 14 | void onComplete(Coroutine c) { 15 | try { 16 | var result = c.returnValue; 17 | } catch (System.Exception ex) { 18 | exception = ex; 19 | } 20 | } 21 | 22 | IEnumerator coroutine() { 23 | yield return new WaitForSeconds(0.1f); 24 | string s = null; 25 | s.ToUpper(); 26 | yield return s; 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/CoroutineGetsExceptionTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 07a45e5a079f6489b94588c63a5eb9df 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/CoroutineGetsLastYieldTest.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using UnityEngine; 3 | using Promises; 4 | 5 | public class CoroutineGetsLastYieldTest : MonoBehaviour { 6 | 7 | public int result; 8 | 9 | void Start() { 10 | CoroutineRunner.StartRoutine(coroutine(), onComplete); 11 | } 12 | 13 | void onComplete(Coroutine c) { 14 | result = c.returnValue; 15 | } 16 | 17 | IEnumerator coroutine() { 18 | yield return new WaitForSeconds(0.1f); 19 | yield return null; 20 | yield return "hello"; 21 | yield return 42; 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/CoroutineGetsLastYieldTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3e3b781ec9f5840fd8b202f063b8069f 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/CoroutineGetsLastestValueBeforeYieldBreakTest.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using UnityEngine; 3 | using Promises; 4 | 5 | public class CoroutineGetsLastestValueBeforeYieldBreakTest : MonoBehaviour { 6 | 7 | public int result; 8 | 9 | void Start() { 10 | CoroutineRunner.StartRoutine(coroutine(), onComplete); 11 | } 12 | 13 | void onComplete(Coroutine c) { 14 | result = c.returnValue; 15 | } 16 | 17 | IEnumerator coroutine() { 18 | var i = 0; 19 | while (true) { 20 | if (i == 10) { 21 | yield break; 22 | } 23 | i++; 24 | yield return i; 25 | } 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/CoroutineGetsLastestValueBeforeYieldBreakTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d78f5c70846304572875b82c5313bdef 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/CoroutineGetsNullTest.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using UnityEngine; 3 | using Promises; 4 | 5 | public class CoroutineGetsNullTest : MonoBehaviour { 6 | 7 | public string result = "result"; 8 | 9 | void Start() { 10 | CoroutineRunner.StartRoutine(coroutine(), onComplete); 11 | } 12 | 13 | void onComplete(Coroutine c) { 14 | result = c.returnValue; 15 | } 16 | 17 | IEnumerator coroutine() { 18 | yield return new WaitForSeconds(0.1f); 19 | yield return null; 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/CoroutineGetsNullTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9a7c790193d28416f951346600dfa010 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/CoroutineGetsValueTest.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using UnityEngine; 3 | using Promises; 4 | 5 | public class CoroutineGetsValueTest : MonoBehaviour { 6 | 7 | public string result; 8 | 9 | void Start() { 10 | CoroutineRunner.StartRoutine(coroutine(), onComplete); 11 | } 12 | 13 | void onComplete(Coroutine c) { 14 | result = c.returnValue; 15 | } 16 | 17 | IEnumerator coroutine() { 18 | yield return new WaitForSeconds(0.1f); 19 | yield return "fourty-two"; 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/CoroutineGetsValueTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ad20faa9fc0b44f3892b988ca97026c9 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/CoroutinePromiseOnFailedCalledTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using UnityEngine; 4 | using Promises; 5 | 6 | public class CoroutinePromiseOnFailedCalledTest : MonoBehaviour { 7 | 8 | public Exception result; 9 | 10 | void Start() { 11 | MainThreadDispatcher.Init(); 12 | Promise.WithCoroutine(coroutine).OnFailed += error => result = error; 13 | } 14 | 15 | IEnumerator coroutine() { 16 | yield return new WaitForSeconds(0.1f); 17 | string s = null; 18 | s.ToUpper(); 19 | yield return s; 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/CoroutinePromiseOnFailedCalledTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a7d4259afa5b64cb0bebb9d477cb2c94 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/CoroutinePromiseOnFulfilledCalledTest.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using UnityEngine; 3 | using Promises; 4 | 5 | public class CoroutinePromiseOnFulfilledCalledTest : MonoBehaviour { 6 | 7 | public int result; 8 | 9 | void Start() { 10 | MainThreadDispatcher.Init(); 11 | Promise.WithCoroutine(coroutine).OnFulfilled += r => result = r; 12 | } 13 | 14 | IEnumerator coroutine() { 15 | var i = 0; 16 | while (true) { 17 | if (i == 10) { 18 | yield break; 19 | } 20 | i++; 21 | yield return i; 22 | } 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/CoroutinePromiseOnFulfilledCalledTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ffc779616f20847be92e1f4580694927 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/CoroutinePromiseOnProgressedCalledTest.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using UnityEngine; 3 | using Promises; 4 | 5 | public class CoroutinePromiseOnProgressedCalledTest : MonoBehaviour { 6 | 7 | public float progress; 8 | 9 | void Start() { 10 | MainThreadDispatcher.Init(); 11 | Promise.WithCoroutine(coroutine).OnProgressed += p => progress = p; 12 | } 13 | 14 | IEnumerator coroutine() { 15 | var i = 0; 16 | while (true) { 17 | if (i == 10) { 18 | yield break; 19 | } 20 | i++; 21 | yield return i; 22 | } 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/CoroutinePromiseOnProgressedCalledTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3ac3e896ea961458b9c88f6281036bf0 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/CoroutinePromiseRescueTest.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using UnityEngine; 3 | using Promises; 4 | using System; 5 | 6 | public class CoroutinePromiseRescueTest : MonoBehaviour { 7 | 8 | public int result; 9 | 10 | void Start() { 11 | MainThreadDispatcher.Init(); 12 | Promise.WithCoroutine(coroutine) 13 | .RescueCoroutine(rescueCoroutine) 14 | .OnFulfilled += r => result = r; 15 | } 16 | 17 | IEnumerator coroutine() { 18 | yield return new WaitForSeconds(0.1f); 19 | string s = null; 20 | s.ToUpper(); 21 | yield return s; 22 | } 23 | 24 | IEnumerator rescueCoroutine(Exception ex) { 25 | var startIndex = 50; 26 | var endIndex = startIndex + 10; 27 | while (true) { 28 | if (startIndex == endIndex) { 29 | yield break; 30 | } 31 | startIndex++; 32 | yield return startIndex; 33 | } 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/CoroutinePromiseRescueTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cd7abf4662387441f8830009f3bd99d0 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/CoroutinePromiseThenTest.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using UnityEngine; 3 | using Promises; 4 | 5 | public class CoroutinePromiseThenTest : MonoBehaviour { 6 | 7 | public int result; 8 | 9 | void Start() { 10 | MainThreadDispatcher.Init(); 11 | Promise.WithCoroutine(coroutine) 12 | .ThenCoroutine(thenCoroutine) 13 | .OnFulfilled += r => result = r; 14 | } 15 | 16 | IEnumerator coroutine() { 17 | var startIndex = 0; 18 | var endIndex = 10; 19 | while (true) { 20 | if (startIndex == endIndex) { 21 | yield break; 22 | } 23 | startIndex++; 24 | yield return startIndex; 25 | } 26 | } 27 | 28 | IEnumerator thenCoroutine(int startIndex) { 29 | var endIndex = startIndex + 10; 30 | while (true) { 31 | if (startIndex == endIndex) { 32 | yield break; 33 | } 34 | startIndex++; 35 | yield return startIndex; 36 | } 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/CoroutinePromiseThenTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7e9b706dfd63641d6aac3878751f6ec2 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/CoroutinePromiseWithArgsTest.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using UnityEngine; 3 | using Promises; 4 | 5 | public class CoroutinePromiseWithArgsTest : MonoBehaviour { 6 | 7 | public int result; 8 | 9 | void Start() { 10 | MainThreadDispatcher.Init(); 11 | Promise.WithCoroutine(() => coroutine(10)).OnFulfilled += r => result = r; 12 | } 13 | 14 | IEnumerator coroutine(int endIndex) { 15 | var i = 0; 16 | while (true) { 17 | if (i == endIndex) { 18 | yield break; 19 | } 20 | i++; 21 | yield return i; 22 | } 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/CoroutinePromiseWithArgsTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 885c1042f2dd646cda6bf3b0278ae09e 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/PromiseCleansUpOnFailedTest.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using Promises; 3 | using System.Threading; 4 | using System; 5 | 6 | public class PromiseCleansUpOnFailedTest : MonoBehaviour { 7 | 8 | public int promises; 9 | 10 | PromiseService _promiseService; 11 | 12 | void Start() { 13 | Promise.WithAction(() => { 14 | Thread.Sleep(100); 15 | throw new Exception("error 42"); 16 | return 42; 17 | }).QueueOnMainThread(onFulfilled); 18 | 19 | _promiseService = UnityEngine.Object.FindObjectOfType(); 20 | } 21 | 22 | void Update() { 23 | promises = _promiseService.promises; 24 | } 25 | 26 | void onFulfilled(int result) { 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/PromiseCleansUpOnFailedTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f03d35f58f6d04af6b976ad06c0f2df9 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/PromiseCleansUpOnFulfilledTest.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using Promises; 3 | using System.Threading; 4 | 5 | public class PromiseCleansUpOnFulfilledTest : MonoBehaviour { 6 | 7 | public int promises; 8 | 9 | PromiseService _promiseService; 10 | 11 | void Start() { 12 | Promise.WithAction(() => { 13 | Thread.Sleep(100); 14 | return 42; 15 | }).QueueOnMainThread(null, onFailed); 16 | 17 | _promiseService = UnityEngine.Object.FindObjectOfType(); 18 | 19 | } 20 | 21 | void Update() { 22 | promises = _promiseService.promises; 23 | } 24 | 25 | void onFailed(System.Exception error) { 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/PromiseCleansUpOnFulfilledTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c1246a789e44b4c08bfacbe2a92db598 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/PromiseOnFailedCalledTest.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using Promises; 3 | using System.Threading; 4 | using System; 5 | 6 | public class PromiseOnFailedCalledTest : MonoBehaviour { 7 | 8 | public string errorMsg; 9 | 10 | void Start() { 11 | Promise.WithAction(() => { 12 | Thread.Sleep(100); 13 | throw new Exception("error 42"); 14 | return 42; 15 | }).QueueOnMainThread(null, onFailed); 16 | } 17 | 18 | void onFailed(Exception e) { 19 | errorMsg = e.Message; 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/PromiseOnFailedCalledTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0ff382f3d108043d4a45479413fc309d 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/PromiseOnFulfilledCalledTest.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using Promises; 3 | using System.Threading; 4 | 5 | public class PromiseOnFulfilledCalledTest : MonoBehaviour { 6 | 7 | public int result; 8 | 9 | void Start() { 10 | Promise.WithAction(() => { 11 | Thread.Sleep(100); 12 | return 42; 13 | }).QueueOnMainThread(onFulfilled); 14 | } 15 | 16 | void onFulfilled(int r) { 17 | result = r; 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/PromiseOnFulfilledCalledTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 77262319afd3d45268de3643f356ad1f 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/PromiseOnProgressedCalledTest.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using Promises; 3 | using System.Threading; 4 | 5 | public class PromiseOnProgressedCalledTest : MonoBehaviour { 6 | 7 | public float progress; 8 | 9 | void Start() { 10 | var d = new Deferred(); 11 | d.action = () => { 12 | while (d.progress < 1) { 13 | Thread.Sleep(100); 14 | d.Progress(d.progress + 0.4f); 15 | } 16 | 17 | return 42; 18 | }; 19 | 20 | d.RunAsync().QueueOnMainThread(null, null, onProgressed); 21 | } 22 | 23 | void onProgressed(float p) { 24 | progress = p; 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/PromiseOnProgressedCalledTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 90bffd15ae8fd4d20ba2596233f4c691 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/Tests.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschmid/Promises-CSharp/ffa339f53e7a4f32c7785523125b8bb429c193d6/Promises/Assets/Tests/Integration Tests/Tests.unity -------------------------------------------------------------------------------- /Promises/Assets/Tests/Integration Tests/Tests.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 915428c5dc0664ec8b612bab24ef0036 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Promises/Library/AnnotationManager: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschmid/Promises-CSharp/ffa339f53e7a4f32c7785523125b8bb429c193d6/Promises/Library/AnnotationManager -------------------------------------------------------------------------------- /Promises/Library/AssetVersioning.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschmid/Promises-CSharp/ffa339f53e7a4f32c7785523125b8bb429c193d6/Promises/Library/AssetVersioning.db -------------------------------------------------------------------------------- /Promises/Library/BuildPlayer.prefs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschmid/Promises-CSharp/ffa339f53e7a4f32c7785523125b8bb429c193d6/Promises/Library/BuildPlayer.prefs -------------------------------------------------------------------------------- /Promises/Library/BuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschmid/Promises-CSharp/ffa339f53e7a4f32c7785523125b8bb429c193d6/Promises/Library/BuildSettings.asset -------------------------------------------------------------------------------- /Promises/Library/EditorUserSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschmid/Promises-CSharp/ffa339f53e7a4f32c7785523125b8bb429c193d6/Promises/Library/EditorUserSettings.asset -------------------------------------------------------------------------------- /Promises/Library/LibraryFormatVersion.txt: -------------------------------------------------------------------------------- 1 | unityRebuildLibraryVersion: 10 2 | unityForwardCompatibleVersion: 40 3 | -------------------------------------------------------------------------------- /Promises/Library/MonoManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschmid/Promises-CSharp/ffa339f53e7a4f32c7785523125b8bb429c193d6/Promises/Library/MonoManager.asset -------------------------------------------------------------------------------- /Promises/Library/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschmid/Promises-CSharp/ffa339f53e7a4f32c7785523125b8bb429c193d6/Promises/Library/ProjectSettings.asset -------------------------------------------------------------------------------- /Promises/ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschmid/Promises-CSharp/ffa339f53e7a4f32c7785523125b8bb429c193d6/Promises/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /Promises/ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschmid/Promises-CSharp/ffa339f53e7a4f32c7785523125b8bb429c193d6/Promises/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /Promises/ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschmid/Promises-CSharp/ffa339f53e7a4f32c7785523125b8bb429c193d6/Promises/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /Promises/ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschmid/Promises-CSharp/ffa339f53e7a4f32c7785523125b8bb429c193d6/Promises/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /Promises/ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschmid/Promises-CSharp/ffa339f53e7a4f32c7785523125b8bb429c193d6/Promises/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /Promises/ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschmid/Promises-CSharp/ffa339f53e7a4f32c7785523125b8bb429c193d6/Promises/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /Promises/ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschmid/Promises-CSharp/ffa339f53e7a4f32c7785523125b8bb429c193d6/Promises/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /Promises/ProjectSettings/NavMeshLayers.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschmid/Promises-CSharp/ffa339f53e7a4f32c7785523125b8bb429c193d6/Promises/ProjectSettings/NavMeshLayers.asset -------------------------------------------------------------------------------- /Promises/ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschmid/Promises-CSharp/ffa339f53e7a4f32c7785523125b8bb429c193d6/Promises/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /Promises/ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschmid/Promises-CSharp/ffa339f53e7a4f32c7785523125b8bb429c193d6/Promises/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /Promises/ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschmid/Promises-CSharp/ffa339f53e7a4f32c7785523125b8bb429c193d6/Promises/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /Promises/ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschmid/Promises-CSharp/ffa339f53e7a4f32c7785523125b8bb429c193d6/Promises/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /Promises/ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschmid/Promises-CSharp/ffa339f53e7a4f32c7785523125b8bb429c193d6/Promises/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /Promises/ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschmid/Promises-CSharp/ffa339f53e7a4f32c7785523125b8bb429c193d6/Promises/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /Promises/Promises-Unity-csharp.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 11.00 2 | # Visual Studio 2008 3 | 4 | Project("{13E5DD6E-461E-4BF0-134D-65EC3837F53E}") = "Promises-Unity", "Assembly-CSharp-vs.csproj", "{FD90446E-9934-6321-E8FD-1F8C04570963}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {FD90446E-9934-6321-E8FD-1F8C04570963}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {FD90446E-9934-6321-E8FD-1F8C04570963}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {FD90446E-9934-6321-E8FD-1F8C04570963}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {FD90446E-9934-6321-E8FD-1F8C04570963}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | GlobalSection(MonoDevelopProperties) = preSolution 21 | StartupItem = Assembly-CSharp.csproj 22 | Policies = $0 23 | $0.TextStylePolicy = $1 24 | $1.inheritsSet = VisualStudio 25 | $1.inheritsScope = text/plain 26 | $1.scope = text/x-csharp 27 | $0.CSharpFormattingPolicy = $2 28 | $2.IndentSwitchBody = True 29 | $2.AutoPropertyFormatting = ForceOneLine 30 | $2.NamespaceBraceStyle = EndOfLine 31 | $2.ClassBraceStyle = EndOfLine 32 | $2.InterfaceBraceStyle = EndOfLine 33 | $2.StructBraceStyle = EndOfLine 34 | $2.EnumBraceStyle = EndOfLine 35 | $2.MethodBraceStyle = EndOfLine 36 | $2.ConstructorBraceStyle = EndOfLine 37 | $2.DestructorBraceStyle = EndOfLine 38 | $2.BeforeMethodDeclarationParentheses = False 39 | $2.BeforeMethodCallParentheses = False 40 | $2.BeforeConstructorDeclarationParentheses = False 41 | $2.BeforeIndexerDeclarationBracket = False 42 | $2.BeforeDelegateDeclarationParentheses = False 43 | $2.AfterDelegateDeclarationParameterComma = True 44 | $2.NewParentheses = False 45 | $2.SpacesBeforeBrackets = False 46 | $2.BlankLinesBeforeUsings = 1 47 | $2.AlignToFirstIndexerDeclarationParameter = False 48 | $2.inheritsSet = Mono 49 | $2.inheritsScope = text/x-csharp 50 | $2.scope = text/x-csharp 51 | $0.TextStylePolicy = $3 52 | $3.inheritsSet = VisualStudio 53 | $3.inheritsScope = text/plain 54 | $3.scope = text/plain 55 | $0.DotNetNamingPolicy = $4 56 | $4.DirectoryNamespaceAssociation = None 57 | $4.ResourceNamePolicy = FileName 58 | $0.StandardHeader = $5 59 | $5.Text = 60 | $5.IncludeInNewFiles = True 61 | $0.NameConventionPolicy = $6 62 | $6.Rules = $7 63 | $7.NamingRule = $8 64 | $8.Name = Namespaces 65 | $8.AffectedEntity = Namespace 66 | $8.VisibilityMask = VisibilityMask 67 | $8.NamingStyle = PascalCase 68 | $8.IncludeInstanceMembers = True 69 | $8.IncludeStaticEntities = True 70 | $7.NamingRule = $9 71 | $9.Name = Types 72 | $9.AffectedEntity = Class, Struct, Enum, Delegate 73 | $9.VisibilityMask = VisibilityMask 74 | $9.NamingStyle = PascalCase 75 | $9.IncludeInstanceMembers = True 76 | $9.IncludeStaticEntities = True 77 | $7.NamingRule = $10 78 | $10.Name = Interfaces 79 | $10.RequiredPrefixes = $11 80 | $11.String = I 81 | $10.AffectedEntity = Interface 82 | $10.VisibilityMask = VisibilityMask 83 | $10.NamingStyle = PascalCase 84 | $10.IncludeInstanceMembers = True 85 | $10.IncludeStaticEntities = True 86 | $7.NamingRule = $12 87 | $12.Name = Attributes 88 | $12.RequiredSuffixes = $13 89 | $13.String = Attribute 90 | $12.AffectedEntity = CustomAttributes 91 | $12.VisibilityMask = VisibilityMask 92 | $12.NamingStyle = PascalCase 93 | $12.IncludeInstanceMembers = True 94 | $12.IncludeStaticEntities = True 95 | $7.NamingRule = $14 96 | $14.Name = Event Arguments 97 | $14.RequiredSuffixes = $15 98 | $15.String = EventArgs 99 | $14.AffectedEntity = CustomEventArgs 100 | $14.VisibilityMask = VisibilityMask 101 | $14.NamingStyle = PascalCase 102 | $14.IncludeInstanceMembers = True 103 | $14.IncludeStaticEntities = True 104 | $7.NamingRule = $16 105 | $16.Name = Exceptions 106 | $16.RequiredSuffixes = $17 107 | $17.String = Exception 108 | $16.AffectedEntity = CustomExceptions 109 | $16.VisibilityMask = VisibilityMask 110 | $16.NamingStyle = PascalCase 111 | $16.IncludeInstanceMembers = True 112 | $16.IncludeStaticEntities = True 113 | $7.NamingRule = $18 114 | $18.Name = Methods (Public) 115 | $18.AffectedEntity = Methods 116 | $18.VisibilityMask = Public 117 | $18.NamingStyle = PascalCase 118 | $18.IncludeInstanceMembers = True 119 | $18.IncludeStaticEntities = True 120 | $7.NamingRule = $19 121 | $19.Name = Static Readonly Fields 122 | $19.AffectedEntity = ReadonlyField 123 | $19.VisibilityMask = Internal, Protected, Public 124 | $19.NamingStyle = CamelCase 125 | $19.IncludeInstanceMembers = False 126 | $19.IncludeStaticEntities = True 127 | $7.NamingRule = $20 128 | $20.Name = Fields (Non Private) 129 | $20.AffectedEntity = Field 130 | $20.VisibilityMask = Internal, Protected, Public 131 | $20.NamingStyle = CamelCase 132 | $20.IncludeInstanceMembers = True 133 | $20.IncludeStaticEntities = True 134 | $7.NamingRule = $21 135 | $21.Name = ReadOnly Fields (Non Private) 136 | $21.AffectedEntity = ReadonlyField 137 | $21.VisibilityMask = Internal, Protected, Public 138 | $21.NamingStyle = CamelCase 139 | $21.IncludeInstanceMembers = True 140 | $21.IncludeStaticEntities = False 141 | $7.NamingRule = $22 142 | $22.Name = Fields (Private) 143 | $22.RequiredPrefixes = $23 144 | $23.String = _ 145 | $22.AffectedEntity = Field, ReadonlyField 146 | $22.VisibilityMask = Private 147 | $22.NamingStyle = CamelCase 148 | $22.IncludeInstanceMembers = True 149 | $22.IncludeStaticEntities = False 150 | $7.NamingRule = $24 151 | $24.Name = Static Fields (Private) 152 | $24.AffectedEntity = Field 153 | $24.VisibilityMask = Private 154 | $24.NamingStyle = CamelCase 155 | $24.IncludeInstanceMembers = False 156 | $24.IncludeStaticEntities = True 157 | $7.NamingRule = $25 158 | $25.Name = ReadOnly Fields (Private) 159 | $25.RequiredPrefixes = $26 160 | $26.String = _ 161 | $25.AffectedEntity = ReadonlyField 162 | $25.VisibilityMask = Private 163 | $25.NamingStyle = CamelCase 164 | $25.IncludeInstanceMembers = True 165 | $25.IncludeStaticEntities = False 166 | $7.NamingRule = $27 167 | $27.Name = Constant Fields 168 | $27.AffectedEntity = ConstantField 169 | $27.VisibilityMask = VisibilityMask 170 | $27.NamingStyle = CamelCase 171 | $27.IncludeInstanceMembers = True 172 | $27.IncludeStaticEntities = True 173 | $7.NamingRule = $28 174 | $28.Name = Properties 175 | $28.AffectedEntity = Property 176 | $28.VisibilityMask = VisibilityMask 177 | $28.NamingStyle = CamelCase 178 | $28.IncludeInstanceMembers = True 179 | $28.IncludeStaticEntities = True 180 | $7.NamingRule = $29 181 | $29.Name = Events 182 | $29.AffectedEntity = Event 183 | $29.VisibilityMask = VisibilityMask 184 | $29.NamingStyle = PascalCase 185 | $29.IncludeInstanceMembers = True 186 | $29.IncludeStaticEntities = True 187 | $7.NamingRule = $30 188 | $30.Name = Enum Members 189 | $30.AffectedEntity = EnumMember 190 | $30.VisibilityMask = VisibilityMask 191 | $30.NamingStyle = PascalCase 192 | $30.IncludeInstanceMembers = True 193 | $30.IncludeStaticEntities = True 194 | $7.NamingRule = $31 195 | $31.Name = Parameters 196 | $31.AffectedEntity = Parameter 197 | $31.VisibilityMask = VisibilityMask 198 | $31.NamingStyle = CamelCase 199 | $31.IncludeInstanceMembers = True 200 | $31.IncludeStaticEntities = True 201 | $7.NamingRule = $32 202 | $32.Name = Type Parameters 203 | $32.RequiredPrefixes = $33 204 | $33.String = T 205 | $32.AffectedEntity = TypeParameter 206 | $32.VisibilityMask = VisibilityMask 207 | $32.NamingStyle = PascalCase 208 | $32.IncludeInstanceMembers = True 209 | $32.IncludeStaticEntities = True 210 | $7.NamingRule = $34 211 | $34.Name = Methods 212 | $34.AffectedEntity = Methods 213 | $34.VisibilityMask = Private, Internal, Protected 214 | $34.NamingStyle = CamelCase 215 | $34.IncludeInstanceMembers = True 216 | $34.IncludeStaticEntities = True 217 | EndGlobalSection 218 | 219 | EndGlobal 220 | -------------------------------------------------------------------------------- /Promises/Promises-Unity.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 11.00 2 | # Visual Studio 2008 3 | 4 | Project("{13E5DD6E-461E-4BF0-134D-65EC3837F53E}") = "Promises-Unity", "Assembly-CSharp.csproj", "{FD90446E-9934-6321-E8FD-1F8C04570963}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {FD90446E-9934-6321-E8FD-1F8C04570963}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {FD90446E-9934-6321-E8FD-1F8C04570963}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {FD90446E-9934-6321-E8FD-1F8C04570963}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {FD90446E-9934-6321-E8FD-1F8C04570963}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | GlobalSection(MonoDevelopProperties) = preSolution 21 | StartupItem = Assembly-CSharp.csproj 22 | Policies = $0 23 | $0.TextStylePolicy = $1 24 | $1.inheritsSet = VisualStudio 25 | $1.inheritsScope = text/plain 26 | $1.scope = text/x-csharp 27 | $0.CSharpFormattingPolicy = $2 28 | $2.IndentSwitchBody = True 29 | $2.AutoPropertyFormatting = ForceOneLine 30 | $2.NamespaceBraceStyle = EndOfLine 31 | $2.ClassBraceStyle = EndOfLine 32 | $2.InterfaceBraceStyle = EndOfLine 33 | $2.StructBraceStyle = EndOfLine 34 | $2.EnumBraceStyle = EndOfLine 35 | $2.MethodBraceStyle = EndOfLine 36 | $2.ConstructorBraceStyle = EndOfLine 37 | $2.DestructorBraceStyle = EndOfLine 38 | $2.BeforeMethodDeclarationParentheses = False 39 | $2.BeforeMethodCallParentheses = False 40 | $2.BeforeConstructorDeclarationParentheses = False 41 | $2.BeforeIndexerDeclarationBracket = False 42 | $2.BeforeDelegateDeclarationParentheses = False 43 | $2.AfterDelegateDeclarationParameterComma = True 44 | $2.NewParentheses = False 45 | $2.SpacesBeforeBrackets = False 46 | $2.BlankLinesBeforeUsings = 1 47 | $2.AlignToFirstIndexerDeclarationParameter = False 48 | $2.inheritsSet = Mono 49 | $2.inheritsScope = text/x-csharp 50 | $2.scope = text/x-csharp 51 | $0.TextStylePolicy = $3 52 | $3.inheritsSet = VisualStudio 53 | $3.inheritsScope = text/plain 54 | $3.scope = text/plain 55 | $0.DotNetNamingPolicy = $4 56 | $4.DirectoryNamespaceAssociation = None 57 | $4.ResourceNamePolicy = FileName 58 | $0.StandardHeader = $5 59 | $5.Text = 60 | $5.IncludeInNewFiles = True 61 | $0.NameConventionPolicy = $6 62 | $6.Rules = $7 63 | $7.NamingRule = $8 64 | $8.Name = Namespaces 65 | $8.AffectedEntity = Namespace 66 | $8.VisibilityMask = VisibilityMask 67 | $8.NamingStyle = PascalCase 68 | $8.IncludeInstanceMembers = True 69 | $8.IncludeStaticEntities = True 70 | $7.NamingRule = $9 71 | $9.Name = Types 72 | $9.AffectedEntity = Class, Struct, Enum, Delegate 73 | $9.VisibilityMask = VisibilityMask 74 | $9.NamingStyle = PascalCase 75 | $9.IncludeInstanceMembers = True 76 | $9.IncludeStaticEntities = True 77 | $7.NamingRule = $10 78 | $10.Name = Interfaces 79 | $10.RequiredPrefixes = $11 80 | $11.String = I 81 | $10.AffectedEntity = Interface 82 | $10.VisibilityMask = VisibilityMask 83 | $10.NamingStyle = PascalCase 84 | $10.IncludeInstanceMembers = True 85 | $10.IncludeStaticEntities = True 86 | $7.NamingRule = $12 87 | $12.Name = Attributes 88 | $12.RequiredSuffixes = $13 89 | $13.String = Attribute 90 | $12.AffectedEntity = CustomAttributes 91 | $12.VisibilityMask = VisibilityMask 92 | $12.NamingStyle = PascalCase 93 | $12.IncludeInstanceMembers = True 94 | $12.IncludeStaticEntities = True 95 | $7.NamingRule = $14 96 | $14.Name = Event Arguments 97 | $14.RequiredSuffixes = $15 98 | $15.String = EventArgs 99 | $14.AffectedEntity = CustomEventArgs 100 | $14.VisibilityMask = VisibilityMask 101 | $14.NamingStyle = PascalCase 102 | $14.IncludeInstanceMembers = True 103 | $14.IncludeStaticEntities = True 104 | $7.NamingRule = $16 105 | $16.Name = Exceptions 106 | $16.RequiredSuffixes = $17 107 | $17.String = Exception 108 | $16.AffectedEntity = CustomExceptions 109 | $16.VisibilityMask = VisibilityMask 110 | $16.NamingStyle = PascalCase 111 | $16.IncludeInstanceMembers = True 112 | $16.IncludeStaticEntities = True 113 | $7.NamingRule = $18 114 | $18.Name = Methods (Public) 115 | $18.AffectedEntity = Methods 116 | $18.VisibilityMask = Public 117 | $18.NamingStyle = PascalCase 118 | $18.IncludeInstanceMembers = True 119 | $18.IncludeStaticEntities = True 120 | $7.NamingRule = $19 121 | $19.Name = Static Readonly Fields 122 | $19.AffectedEntity = ReadonlyField 123 | $19.VisibilityMask = Internal, Protected, Public 124 | $19.NamingStyle = CamelCase 125 | $19.IncludeInstanceMembers = False 126 | $19.IncludeStaticEntities = True 127 | $7.NamingRule = $20 128 | $20.Name = Fields (Non Private) 129 | $20.AffectedEntity = Field 130 | $20.VisibilityMask = Internal, Protected, Public 131 | $20.NamingStyle = CamelCase 132 | $20.IncludeInstanceMembers = True 133 | $20.IncludeStaticEntities = True 134 | $7.NamingRule = $21 135 | $21.Name = ReadOnly Fields (Non Private) 136 | $21.AffectedEntity = ReadonlyField 137 | $21.VisibilityMask = Internal, Protected, Public 138 | $21.NamingStyle = CamelCase 139 | $21.IncludeInstanceMembers = True 140 | $21.IncludeStaticEntities = False 141 | $7.NamingRule = $22 142 | $22.Name = Fields (Private) 143 | $22.RequiredPrefixes = $23 144 | $23.String = _ 145 | $22.AffectedEntity = Field, ReadonlyField 146 | $22.VisibilityMask = Private 147 | $22.NamingStyle = CamelCase 148 | $22.IncludeInstanceMembers = True 149 | $22.IncludeStaticEntities = False 150 | $7.NamingRule = $24 151 | $24.Name = Static Fields (Private) 152 | $24.AffectedEntity = Field 153 | $24.VisibilityMask = Private 154 | $24.NamingStyle = CamelCase 155 | $24.IncludeInstanceMembers = False 156 | $24.IncludeStaticEntities = True 157 | $7.NamingRule = $25 158 | $25.Name = ReadOnly Fields (Private) 159 | $25.RequiredPrefixes = $26 160 | $26.String = _ 161 | $25.AffectedEntity = ReadonlyField 162 | $25.VisibilityMask = Private 163 | $25.NamingStyle = CamelCase 164 | $25.IncludeInstanceMembers = True 165 | $25.IncludeStaticEntities = False 166 | $7.NamingRule = $27 167 | $27.Name = Constant Fields 168 | $27.AffectedEntity = ConstantField 169 | $27.VisibilityMask = VisibilityMask 170 | $27.NamingStyle = CamelCase 171 | $27.IncludeInstanceMembers = True 172 | $27.IncludeStaticEntities = True 173 | $7.NamingRule = $28 174 | $28.Name = Properties 175 | $28.AffectedEntity = Property 176 | $28.VisibilityMask = VisibilityMask 177 | $28.NamingStyle = CamelCase 178 | $28.IncludeInstanceMembers = True 179 | $28.IncludeStaticEntities = True 180 | $7.NamingRule = $29 181 | $29.Name = Events 182 | $29.AffectedEntity = Event 183 | $29.VisibilityMask = VisibilityMask 184 | $29.NamingStyle = PascalCase 185 | $29.IncludeInstanceMembers = True 186 | $29.IncludeStaticEntities = True 187 | $7.NamingRule = $30 188 | $30.Name = Enum Members 189 | $30.AffectedEntity = EnumMember 190 | $30.VisibilityMask = VisibilityMask 191 | $30.NamingStyle = PascalCase 192 | $30.IncludeInstanceMembers = True 193 | $30.IncludeStaticEntities = True 194 | $7.NamingRule = $31 195 | $31.Name = Parameters 196 | $31.AffectedEntity = Parameter 197 | $31.VisibilityMask = VisibilityMask 198 | $31.NamingStyle = CamelCase 199 | $31.IncludeInstanceMembers = True 200 | $31.IncludeStaticEntities = True 201 | $7.NamingRule = $32 202 | $32.Name = Type Parameters 203 | $32.RequiredPrefixes = $33 204 | $33.String = T 205 | $32.AffectedEntity = TypeParameter 206 | $32.VisibilityMask = VisibilityMask 207 | $32.NamingStyle = PascalCase 208 | $32.IncludeInstanceMembers = True 209 | $32.IncludeStaticEntities = True 210 | $7.NamingRule = $34 211 | $34.Name = Methods 212 | $34.AffectedEntity = Methods 213 | $34.VisibilityMask = Private, Internal, Protected 214 | $34.NamingStyle = CamelCase 215 | $34.IncludeInstanceMembers = True 216 | $34.IncludeStaticEntities = True 217 | EndGlobalSection 218 | 219 | EndGlobal 220 | -------------------------------------------------------------------------------- /Promises/Promises-csharp.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 11.00 2 | # Visual Studio 2008 3 | 4 | Project("{1559DDE7-2458-E3D2-5B23-95666393D805}") = "Promises", "Assembly-CSharp-vs.csproj", "{078E3FFF-5273-27E8-12B5-6C83568FAB85}" 5 | EndProject 6 | Project("{1559DDE7-2458-E3D2-5B23-95666393D805}") = "Promises", "Assembly-CSharp-Editor-vs.csproj", "{DBE831DB-43D2-FC62-AE1C-4DE8C845CAA0}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {078E3FFF-5273-27E8-12B5-6C83568FAB85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {078E3FFF-5273-27E8-12B5-6C83568FAB85}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {078E3FFF-5273-27E8-12B5-6C83568FAB85}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {078E3FFF-5273-27E8-12B5-6C83568FAB85}.Release|Any CPU.Build.0 = Release|Any CPU 18 | {DBE831DB-43D2-FC62-AE1C-4DE8C845CAA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {DBE831DB-43D2-FC62-AE1C-4DE8C845CAA0}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {DBE831DB-43D2-FC62-AE1C-4DE8C845CAA0}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {DBE831DB-43D2-FC62-AE1C-4DE8C845CAA0}.Release|Any CPU.Build.0 = Release|Any CPU 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | GlobalSection(MonoDevelopProperties) = preSolution 27 | Policies = $0 28 | $0.TextStylePolicy = $1 29 | $1.inheritsSet = VisualStudio 30 | $1.inheritsScope = text/plain 31 | $1.scope = text/x-csharp 32 | $0.CSharpFormattingPolicy = $2 33 | $2.IndentSwitchBody = True 34 | $2.AutoPropertyFormatting = ForceOneLine 35 | $2.NamespaceBraceStyle = EndOfLine 36 | $2.ClassBraceStyle = EndOfLine 37 | $2.InterfaceBraceStyle = EndOfLine 38 | $2.StructBraceStyle = EndOfLine 39 | $2.EnumBraceStyle = EndOfLine 40 | $2.MethodBraceStyle = EndOfLine 41 | $2.ConstructorBraceStyle = EndOfLine 42 | $2.DestructorBraceStyle = EndOfLine 43 | $2.BeforeMethodDeclarationParentheses = False 44 | $2.BeforeMethodCallParentheses = False 45 | $2.BeforeConstructorDeclarationParentheses = False 46 | $2.BeforeIndexerDeclarationBracket = False 47 | $2.BeforeDelegateDeclarationParentheses = False 48 | $2.AfterDelegateDeclarationParameterComma = True 49 | $2.NewParentheses = False 50 | $2.SpacesBeforeBrackets = False 51 | $2.BlankLinesBeforeUsings = 1 52 | $2.AlignToFirstIndexerDeclarationParameter = False 53 | $2.inheritsSet = Mono 54 | $2.inheritsScope = text/x-csharp 55 | $2.scope = text/x-csharp 56 | $0.TextStylePolicy = $3 57 | $3.inheritsSet = VisualStudio 58 | $3.inheritsScope = text/plain 59 | $3.scope = text/plain 60 | $0.DotNetNamingPolicy = $4 61 | $4.DirectoryNamespaceAssociation = None 62 | $4.ResourceNamePolicy = FileName 63 | $0.NameConventionPolicy = $5 64 | $5.Rules = $6 65 | $6.NamingRule = $7 66 | $7.Name = PascalCase 67 | $7.AffectedEntity = Namespace, Class, Struct, Enum, Delegate, Event, EnumMember 68 | $7.VisibilityMask = VisibilityMask 69 | $7.NamingStyle = PascalCase 70 | $7.IncludeInstanceMembers = True 71 | $7.IncludeStaticEntities = True 72 | $6.NamingRule = $8 73 | $8.Name = Interfaces 74 | $8.RequiredPrefixes = $9 75 | $9.String = I 76 | $8.AffectedEntity = Interface 77 | $8.VisibilityMask = VisibilityMask 78 | $8.NamingStyle = PascalCase 79 | $8.IncludeInstanceMembers = True 80 | $8.IncludeStaticEntities = True 81 | $6.NamingRule = $10 82 | $10.Name = Attributes 83 | $10.RequiredSuffixes = $11 84 | $11.String = Attributes 85 | $10.AffectedEntity = CustomAttributes 86 | $10.VisibilityMask = VisibilityMask 87 | $10.NamingStyle = PascalCase 88 | $10.IncludeInstanceMembers = True 89 | $10.IncludeStaticEntities = True 90 | $6.NamingRule = $12 91 | $12.Name = Event Args 92 | $12.RequiredSuffixes = $13 93 | $13.String = EventArgs 94 | $12.AffectedEntity = CustomEventArgs 95 | $12.VisibilityMask = VisibilityMask 96 | $12.NamingStyle = PascalCase 97 | $12.IncludeInstanceMembers = True 98 | $12.IncludeStaticEntities = True 99 | $6.NamingRule = $14 100 | $14.Name = Exceptions 101 | $14.RequiredSuffixes = $15 102 | $15.String = Exception 103 | $14.AffectedEntity = CustomExceptions 104 | $14.VisibilityMask = VisibilityMask 105 | $14.NamingStyle = PascalCase 106 | $14.IncludeInstanceMembers = True 107 | $14.IncludeStaticEntities = True 108 | $6.NamingRule = $16 109 | $16.Name = camelCase 110 | $16.AffectedEntity = Property, ConstantField, LocalVars 111 | $16.VisibilityMask = VisibilityMask 112 | $16.NamingStyle = CamelCase 113 | $16.IncludeInstanceMembers = True 114 | $16.IncludeStaticEntities = True 115 | $6.NamingRule = $17 116 | $17.Name = Fields (non public) 117 | $17.RequiredPrefixes = $18 118 | $18.String = _ 119 | $17.AffectedEntity = Field, ReadonlyField 120 | $17.VisibilityMask = Private, Internal, Protected 121 | $17.NamingStyle = CamelCase 122 | $17.IncludeInstanceMembers = True 123 | $17.IncludeStaticEntities = True 124 | $6.NamingRule = $19 125 | $19.Name = Fields 126 | $19.AffectedEntity = Field, ReadonlyField 127 | $19.VisibilityMask = Public 128 | $19.NamingStyle = CamelCase 129 | $19.IncludeInstanceMembers = True 130 | $19.IncludeStaticEntities = True 131 | $6.NamingRule = $20 132 | $20.Name = Methods (public) 133 | $20.AffectedEntity = Methods 134 | $20.VisibilityMask = Public 135 | $20.NamingStyle = PascalCase 136 | $20.IncludeInstanceMembers = True 137 | $20.IncludeStaticEntities = True 138 | $6.NamingRule = $21 139 | $21.Name = Methods 140 | $21.AffectedEntity = Methods 141 | $21.VisibilityMask = Private, Internal, Protected 142 | $21.NamingStyle = CamelCase 143 | $21.IncludeInstanceMembers = True 144 | $21.IncludeStaticEntities = True 145 | $6.NamingRule = $22 146 | $22.Name = Type Parameters 147 | $22.RequiredPrefixes = $23 148 | $23.String = T 149 | $22.AffectedEntity = TypeParameter 150 | $22.VisibilityMask = VisibilityMask 151 | $22.NamingStyle = PascalCase 152 | $22.IncludeInstanceMembers = True 153 | $22.IncludeStaticEntities = True 154 | EndGlobalSection 155 | 156 | EndGlobal 157 | -------------------------------------------------------------------------------- /Promises/Promises.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 11.00 2 | # Visual Studio 2008 3 | 4 | Project("{1559DDE7-2458-E3D2-5B23-95666393D805}") = "Promises", "Assembly-CSharp.csproj", "{078E3FFF-5273-27E8-12B5-6C83568FAB85}" 5 | EndProject 6 | Project("{1559DDE7-2458-E3D2-5B23-95666393D805}") = "Promises", "Assembly-CSharp-Editor.csproj", "{DBE831DB-43D2-FC62-AE1C-4DE8C845CAA0}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {078E3FFF-5273-27E8-12B5-6C83568FAB85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {078E3FFF-5273-27E8-12B5-6C83568FAB85}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {078E3FFF-5273-27E8-12B5-6C83568FAB85}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {078E3FFF-5273-27E8-12B5-6C83568FAB85}.Release|Any CPU.Build.0 = Release|Any CPU 18 | {DBE831DB-43D2-FC62-AE1C-4DE8C845CAA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {DBE831DB-43D2-FC62-AE1C-4DE8C845CAA0}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {DBE831DB-43D2-FC62-AE1C-4DE8C845CAA0}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {DBE831DB-43D2-FC62-AE1C-4DE8C845CAA0}.Release|Any CPU.Build.0 = Release|Any CPU 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | GlobalSection(MonoDevelopProperties) = preSolution 27 | Policies = $0 28 | $0.TextStylePolicy = $1 29 | $1.inheritsSet = VisualStudio 30 | $1.inheritsScope = text/plain 31 | $1.scope = text/x-csharp 32 | $0.CSharpFormattingPolicy = $2 33 | $2.IndentSwitchBody = True 34 | $2.AutoPropertyFormatting = ForceOneLine 35 | $2.NamespaceBraceStyle = EndOfLine 36 | $2.ClassBraceStyle = EndOfLine 37 | $2.InterfaceBraceStyle = EndOfLine 38 | $2.StructBraceStyle = EndOfLine 39 | $2.EnumBraceStyle = EndOfLine 40 | $2.MethodBraceStyle = EndOfLine 41 | $2.ConstructorBraceStyle = EndOfLine 42 | $2.DestructorBraceStyle = EndOfLine 43 | $2.BeforeMethodDeclarationParentheses = False 44 | $2.BeforeMethodCallParentheses = False 45 | $2.BeforeConstructorDeclarationParentheses = False 46 | $2.BeforeIndexerDeclarationBracket = False 47 | $2.BeforeDelegateDeclarationParentheses = False 48 | $2.AfterDelegateDeclarationParameterComma = True 49 | $2.NewParentheses = False 50 | $2.SpacesBeforeBrackets = False 51 | $2.BlankLinesBeforeUsings = 1 52 | $2.AlignToFirstIndexerDeclarationParameter = False 53 | $2.inheritsSet = Mono 54 | $2.inheritsScope = text/x-csharp 55 | $2.scope = text/x-csharp 56 | $0.TextStylePolicy = $3 57 | $3.inheritsSet = VisualStudio 58 | $3.inheritsScope = text/plain 59 | $3.scope = text/plain 60 | $0.DotNetNamingPolicy = $4 61 | $4.DirectoryNamespaceAssociation = None 62 | $4.ResourceNamePolicy = FileName 63 | $0.NameConventionPolicy = $5 64 | $5.Rules = $6 65 | $6.NamingRule = $7 66 | $7.Name = PascalCase 67 | $7.AffectedEntity = Namespace, Class, Struct, Enum, Delegate, Event, EnumMember 68 | $7.VisibilityMask = VisibilityMask 69 | $7.NamingStyle = PascalCase 70 | $7.IncludeInstanceMembers = True 71 | $7.IncludeStaticEntities = True 72 | $6.NamingRule = $8 73 | $8.Name = Interfaces 74 | $8.RequiredPrefixes = $9 75 | $9.String = I 76 | $8.AffectedEntity = Interface 77 | $8.VisibilityMask = VisibilityMask 78 | $8.NamingStyle = PascalCase 79 | $8.IncludeInstanceMembers = True 80 | $8.IncludeStaticEntities = True 81 | $6.NamingRule = $10 82 | $10.Name = Attributes 83 | $10.RequiredSuffixes = $11 84 | $11.String = Attributes 85 | $10.AffectedEntity = CustomAttributes 86 | $10.VisibilityMask = VisibilityMask 87 | $10.NamingStyle = PascalCase 88 | $10.IncludeInstanceMembers = True 89 | $10.IncludeStaticEntities = True 90 | $6.NamingRule = $12 91 | $12.Name = Event Args 92 | $12.RequiredSuffixes = $13 93 | $13.String = EventArgs 94 | $12.AffectedEntity = CustomEventArgs 95 | $12.VisibilityMask = VisibilityMask 96 | $12.NamingStyle = PascalCase 97 | $12.IncludeInstanceMembers = True 98 | $12.IncludeStaticEntities = True 99 | $6.NamingRule = $14 100 | $14.Name = Exceptions 101 | $14.RequiredSuffixes = $15 102 | $15.String = Exception 103 | $14.AffectedEntity = CustomExceptions 104 | $14.VisibilityMask = VisibilityMask 105 | $14.NamingStyle = PascalCase 106 | $14.IncludeInstanceMembers = True 107 | $14.IncludeStaticEntities = True 108 | $6.NamingRule = $16 109 | $16.Name = camelCase 110 | $16.AffectedEntity = Property, ConstantField, LocalVars 111 | $16.VisibilityMask = VisibilityMask 112 | $16.NamingStyle = CamelCase 113 | $16.IncludeInstanceMembers = True 114 | $16.IncludeStaticEntities = True 115 | $6.NamingRule = $17 116 | $17.Name = Fields (non public) 117 | $17.RequiredPrefixes = $18 118 | $18.String = _ 119 | $17.AffectedEntity = Field, ReadonlyField 120 | $17.VisibilityMask = Private, Internal, Protected 121 | $17.NamingStyle = CamelCase 122 | $17.IncludeInstanceMembers = True 123 | $17.IncludeStaticEntities = True 124 | $6.NamingRule = $19 125 | $19.Name = Fields 126 | $19.AffectedEntity = Field, ReadonlyField 127 | $19.VisibilityMask = Public 128 | $19.NamingStyle = CamelCase 129 | $19.IncludeInstanceMembers = True 130 | $19.IncludeStaticEntities = True 131 | $6.NamingRule = $20 132 | $20.Name = Methods (public) 133 | $20.AffectedEntity = Methods 134 | $20.VisibilityMask = Public 135 | $20.NamingStyle = PascalCase 136 | $20.IncludeInstanceMembers = True 137 | $20.IncludeStaticEntities = True 138 | $6.NamingRule = $21 139 | $21.Name = Methods 140 | $21.AffectedEntity = Methods 141 | $21.VisibilityMask = Private, Internal, Protected 142 | $21.NamingStyle = CamelCase 143 | $21.IncludeInstanceMembers = True 144 | $21.IncludeStaticEntities = True 145 | $6.NamingRule = $22 146 | $22.Name = Type Parameters 147 | $22.RequiredPrefixes = $23 148 | $23.String = T 149 | $22.AffectedEntity = TypeParameter 150 | $22.VisibilityMask = VisibilityMask 151 | $22.NamingStyle = PascalCase 152 | $22.IncludeInstanceMembers = True 153 | $22.IncludeStaticEntities = True 154 | EndGlobalSection 155 | 156 | EndGlobal 157 | -------------------------------------------------------------------------------- /Tests/Libraries/nspec/NSpec.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschmid/Promises-CSharp/ffa339f53e7a4f32c7785523125b8bb429c193d6/Tests/Libraries/nspec/NSpec.dll -------------------------------------------------------------------------------- /Tests/Libraries/nspec/NSpec.dll.mdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschmid/Promises-CSharp/ffa339f53e7a4f32c7785523125b8bb429c193d6/Tests/Libraries/nspec/NSpec.dll.mdb -------------------------------------------------------------------------------- /Tests/Libraries/nspec/NSpecRunner.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschmid/Promises-CSharp/ffa339f53e7a4f32c7785523125b8bb429c193d6/Tests/Libraries/nspec/NSpecRunner.exe -------------------------------------------------------------------------------- /Tests/Libraries/nspec/NSpecRunner.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Tests/Libraries/nspec/NSpecRunner.exe.mdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschmid/Promises-CSharp/ffa339f53e7a4f32c7785523125b8bb429c193d6/Tests/Libraries/nspec/NSpecRunner.exe.mdb -------------------------------------------------------------------------------- /Tests/Libraries/nunit.framework.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschmid/Promises-CSharp/ffa339f53e7a4f32c7785523125b8bb429c193d6/Tests/Libraries/nunit.framework.dll -------------------------------------------------------------------------------- /Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | // Information about this assembly is defined by the following attributes. 5 | // Change them to the values specific to your project. 6 | 7 | [assembly: AssemblyTitle("Tests")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("")] 12 | [assembly: AssemblyCopyright("sschmid")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". 17 | // The form "{Major}.{Minor}.*" will automatically update the build and revision, 18 | // and "{Major}.{Minor}.{Build}.*" will update just the revision. 19 | 20 | [assembly: AssemblyVersion("1.0.*")] 21 | 22 | // The following attributes are used to specify the signing key for the assembly, 23 | // if desired. See the Mono documentation for more information about signing. 24 | 25 | //[assembly: AssemblyDelaySign(false)] 26 | //[assembly: AssemblyKeyFile("")] 27 | 28 | -------------------------------------------------------------------------------- /Tests/Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | {A9F2C1D6-19B1-4B88-95B2-B95585DC2873} 7 | Library 8 | Tests 9 | Tests 10 | 8.0.30703 11 | 2.0 12 | 13 | 14 | true 15 | full 16 | false 17 | bin\Debug 18 | DEBUG; 19 | prompt 20 | 4 21 | false 22 | 23 | 24 | full 25 | true 26 | bin\Release 27 | prompt 28 | 4 29 | false 30 | 31 | 32 | 33 | 34 | Libraries\nunit.framework.dll 35 | 36 | 37 | Libraries\nspec\NSpec.dll 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | {078E3FFF-5273-27E8-12B5-6C83568FAB85} 66 | Assembly-CSharp 67 | 68 | 69 | -------------------------------------------------------------------------------- /Tests/Tests.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests.csproj", "{A9F2C1D6-19B1-4B88-95B2-B95585DC2873}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp", "..\Promises\Assembly-CSharp.csproj", "{078E3FFF-5273-27E8-12B5-6C83568FAB85}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {078E3FFF-5273-27E8-12B5-6C83568FAB85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {078E3FFF-5273-27E8-12B5-6C83568FAB85}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {078E3FFF-5273-27E8-12B5-6C83568FAB85}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {078E3FFF-5273-27E8-12B5-6C83568FAB85}.Release|Any CPU.Build.0 = Release|Any CPU 18 | {A9F2C1D6-19B1-4B88-95B2-B95585DC2873}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {A9F2C1D6-19B1-4B88-95B2-B95585DC2873}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {A9F2C1D6-19B1-4B88-95B2-B95585DC2873}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {A9F2C1D6-19B1-4B88-95B2-B95585DC2873}.Release|Any CPU.Build.0 = Release|Any CPU 22 | EndGlobalSection 23 | GlobalSection(MonoDevelopProperties) = preSolution 24 | Policies = $0 25 | $0.DotNetNamingPolicy = $1 26 | $1.DirectoryNamespaceAssociation = None 27 | $1.ResourceNamePolicy = FileName 28 | $0.TextStylePolicy = $2 29 | $2.inheritsSet = VisualStudio 30 | $2.inheritsScope = text/plain 31 | $2.scope = text/plain 32 | $0.TextStylePolicy = $3 33 | $3.inheritsSet = VisualStudio 34 | $3.inheritsScope = text/plain 35 | $3.scope = text/x-csharp 36 | $0.CSharpFormattingPolicy = $4 37 | $4.IndentSwitchBody = True 38 | $4.AutoPropertyFormatting = ForceOneLine 39 | $4.NamespaceBraceStyle = EndOfLine 40 | $4.ClassBraceStyle = EndOfLine 41 | $4.InterfaceBraceStyle = EndOfLine 42 | $4.StructBraceStyle = EndOfLine 43 | $4.EnumBraceStyle = EndOfLine 44 | $4.MethodBraceStyle = EndOfLine 45 | $4.ConstructorBraceStyle = EndOfLine 46 | $4.DestructorBraceStyle = EndOfLine 47 | $4.BeforeMethodDeclarationParentheses = False 48 | $4.BeforeMethodCallParentheses = False 49 | $4.BeforeConstructorDeclarationParentheses = False 50 | $4.BeforeIndexerDeclarationBracket = False 51 | $4.BeforeDelegateDeclarationParentheses = False 52 | $4.AfterDelegateDeclarationParameterComma = True 53 | $4.NewParentheses = False 54 | $4.SpacesBeforeBrackets = False 55 | $4.BlankLinesBeforeUsings = 1 56 | $4.AlignToFirstIndexerDeclarationParameter = False 57 | $4.inheritsSet = Mono 58 | $4.inheritsScope = text/x-csharp 59 | $4.scope = text/x-csharp 60 | $0.StandardHeader = $5 61 | $5.Text = 62 | $5.IncludeInNewFiles = True 63 | $0.NameConventionPolicy = $6 64 | $6.Rules = $7 65 | $7.NamingRule = $8 66 | $8.Name = PascalCase 67 | $8.AffectedEntity = Namespace, Class, Struct, Enum, Delegate, Event, EnumMember 68 | $8.VisibilityMask = VisibilityMask 69 | $8.NamingStyle = PascalCase 70 | $8.IncludeInstanceMembers = True 71 | $8.IncludeStaticEntities = True 72 | $7.NamingRule = $9 73 | $9.Name = Interfaces 74 | $9.RequiredPrefixes = $10 75 | $10.String = I 76 | $9.AffectedEntity = Interface 77 | $9.VisibilityMask = VisibilityMask 78 | $9.NamingStyle = PascalCase 79 | $9.IncludeInstanceMembers = True 80 | $9.IncludeStaticEntities = True 81 | $7.NamingRule = $11 82 | $11.Name = Attributes 83 | $11.RequiredSuffixes = $12 84 | $12.String = Attributes 85 | $11.AffectedEntity = CustomAttributes 86 | $11.VisibilityMask = VisibilityMask 87 | $11.NamingStyle = PascalCase 88 | $11.IncludeInstanceMembers = True 89 | $11.IncludeStaticEntities = True 90 | $7.NamingRule = $13 91 | $13.Name = Event Args 92 | $13.RequiredSuffixes = $14 93 | $14.String = EventArgs 94 | $13.AffectedEntity = CustomEventArgs 95 | $13.VisibilityMask = VisibilityMask 96 | $13.NamingStyle = PascalCase 97 | $13.IncludeInstanceMembers = True 98 | $13.IncludeStaticEntities = True 99 | $7.NamingRule = $15 100 | $15.Name = Exceptions 101 | $15.RequiredSuffixes = $16 102 | $16.String = Exception 103 | $15.AffectedEntity = CustomExceptions 104 | $15.VisibilityMask = VisibilityMask 105 | $15.NamingStyle = PascalCase 106 | $15.IncludeInstanceMembers = True 107 | $15.IncludeStaticEntities = True 108 | $7.NamingRule = $17 109 | $17.Name = camelCase 110 | $17.AffectedEntity = Property, ConstantField, LocalVars 111 | $17.VisibilityMask = VisibilityMask 112 | $17.NamingStyle = CamelCase 113 | $17.IncludeInstanceMembers = True 114 | $17.IncludeStaticEntities = True 115 | $7.NamingRule = $18 116 | $18.Name = Fields (non public) 117 | $18.RequiredPrefixes = $19 118 | $19.String = _ 119 | $18.AffectedEntity = Field, ReadonlyField 120 | $18.VisibilityMask = Private, Internal, Protected 121 | $18.NamingStyle = CamelCase 122 | $18.IncludeInstanceMembers = True 123 | $18.IncludeStaticEntities = True 124 | $7.NamingRule = $20 125 | $20.Name = Fields 126 | $20.AffectedEntity = Field, ReadonlyField 127 | $20.VisibilityMask = Public 128 | $20.NamingStyle = CamelCase 129 | $20.IncludeInstanceMembers = True 130 | $20.IncludeStaticEntities = True 131 | $7.NamingRule = $21 132 | $21.Name = Methods (public) 133 | $21.AffectedEntity = Methods 134 | $21.VisibilityMask = Public 135 | $21.NamingStyle = PascalCase 136 | $21.IncludeInstanceMembers = True 137 | $21.IncludeStaticEntities = True 138 | $7.NamingRule = $22 139 | $22.Name = Methods 140 | $22.AffectedEntity = Methods 141 | $22.VisibilityMask = Private, Internal, Protected 142 | $22.NamingStyle = CamelCase 143 | $22.IncludeInstanceMembers = True 144 | $22.IncludeStaticEntities = True 145 | $7.NamingRule = $23 146 | $23.Name = Type Parameters 147 | $23.RequiredPrefixes = $24 148 | $24.String = T 149 | $23.AffectedEntity = TypeParameter 150 | $23.VisibilityMask = VisibilityMask 151 | $23.NamingStyle = PascalCase 152 | $23.IncludeInstanceMembers = True 153 | $23.IncludeStaticEntities = True 154 | EndGlobalSection 155 | EndGlobal 156 | -------------------------------------------------------------------------------- /Tests/Tests/TestHelper.cs: -------------------------------------------------------------------------------- 1 | using Promises; 2 | using System; 3 | using System.Threading; 4 | 5 | public static class TestHelper { 6 | public static Promise PromiseWithResult(T result, int delay = 0) { 7 | return Promise.WithAction(() => { 8 | if (delay > 0) 9 | Thread.Sleep(delay); 10 | return result; 11 | }); 12 | } 13 | 14 | public static Promise PromiseWithError(string errorMessage, int delay = 0) { 15 | return Promise.WithAction(() => { 16 | if (delay > 0) 17 | Thread.Sleep(delay); 18 | throw new Exception(errorMessage); 19 | }); 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Tests/Tests/describe_All.cs: -------------------------------------------------------------------------------- 1 | using NSpec; 2 | using Promises; 3 | using System.Collections.Generic; 4 | 5 | class describe_All : nspec { 6 | 7 | const int delay = 5; 8 | 9 | void when_running_in_parallel_with_all() { 10 | 11 | Promise p1 = null; 12 | Promise p2 = null; 13 | Promise promise = null; 14 | List eventProgresses = null; 15 | 16 | context["when all promises fulfill"] = () => { 17 | before = () => { 18 | eventProgresses = new List(); 19 | p1 = TestHelper.PromiseWithResult(42, delay); 20 | p2 = TestHelper.PromiseWithResult("42", 2 * delay); 21 | promise = Promise.All(p1, p2); 22 | promise.OnProgressed += eventProgresses.Add; 23 | promise.Await(); 24 | }; 25 | 26 | it["is fulfilled"] = () => promise.state.should_be(PromiseState.Fulfilled); 27 | it["has progressed 100%"] = () => promise.progress.should_be(1f); 28 | it["has result"] = () => promise.result.should_not_be_null(); 29 | it["has no error"] = () => promise.error.should_be_null(); 30 | it["has results at correct index"] = () => { 31 | (promise.result[0]).should_be(42); 32 | (promise.result[1]).should_be("42"); 33 | }; 34 | 35 | it["calls progress"] = () => { 36 | eventProgresses.Count.should_be(2); 37 | eventProgresses[0].should_be(0.5f); 38 | eventProgresses[1].should_be(1f); 39 | }; 40 | 41 | it["has initial progress"] = () => { 42 | var deferred = new Deferred(); 43 | deferred.Progress(0.5f); 44 | p2 = TestHelper.PromiseWithResult("42", 2 * delay); 45 | promise = Promise.All(deferred, p2); 46 | promise.progress.should_be(0.25f); 47 | deferred.Fulfill(null); 48 | promise.Await(); 49 | }; 50 | }; 51 | 52 | context["when a promise fails"] = () => { 53 | 54 | before = () => { 55 | eventProgresses = new List(); 56 | p1 = TestHelper.PromiseWithResult(42, delay); 57 | p2 = TestHelper.PromiseWithError("error 42", 2 * delay); 58 | promise = Promise.All(p1, p2); 59 | promise.OnProgressed += eventProgresses.Add; 60 | promise.Await(); 61 | }; 62 | 63 | it["failed"] = () => promise.state.should_be(PromiseState.Failed); 64 | it["has progressed 50%"] = () => promise.progress.should_be(0.5f); 65 | it["has no result"] = () => promise.result.should_be_null(); 66 | it["has error"] = () => promise.error.Message.should_be("error 42"); 67 | it["calls progress"] = () => { 68 | eventProgresses.Count.should_be(1); 69 | eventProgresses[0].should_be(0.5f); 70 | }; 71 | }; 72 | } 73 | } 74 | 75 | -------------------------------------------------------------------------------- /Tests/Tests/describe_Any.cs: -------------------------------------------------------------------------------- 1 | using NSpec; 2 | using Promises; 3 | using System.Collections.Generic; 4 | 5 | class describe_Any : nspec { 6 | 7 | const int delay = 5; 8 | 9 | void when_running_in_parallel_with_any() { 10 | Promise p1 = null; 11 | Promise p2 = null; 12 | Promise p3 = null; 13 | Promise p4 = null; 14 | Promise promise = null; 15 | 16 | context["when at least one promise fulfills"] = () => { 17 | List eventProgresses = null; 18 | 19 | before = () => { 20 | p1 = TestHelper.PromiseWithError("error 42", delay); 21 | p2 = TestHelper.PromiseWithResult("42", delay * 2); 22 | p3 = TestHelper.PromiseWithResult("43", delay * 3); 23 | p4 = TestHelper.PromiseWithResult("44", delay * 3); 24 | eventProgresses = new List(); 25 | promise = Promise.Any(p1, p2, p3, p4); 26 | promise.OnProgressed += eventProgresses.Add; 27 | promise.Await(); 28 | }; 29 | 30 | it["is fulfilled"] = () => promise.state.should_be(PromiseState.Fulfilled); 31 | it["first promise to be complete is fulfilled"] = () => p2.state.should_be(PromiseState.Fulfilled); 32 | it["has result of first complete promise"] = () => promise.result.should_be("42"); 33 | 34 | context["progress"] = () => { 35 | it["calculates progress of promise with highest progress"] = () => { 36 | eventProgresses.Count.should_be(1); 37 | eventProgresses[0].should_be(1f); 38 | }; 39 | 40 | it["has initial max progress"] = () => { 41 | var deferred = new Deferred(); 42 | deferred.Progress(0.5f); 43 | var p = TestHelper.PromiseWithResult("42", delay * 2); 44 | var any = Promise.Any(deferred, p); 45 | any.progress.should_be(0.5f); 46 | deferred.Fulfill(null); 47 | any.Await(); 48 | }; 49 | }; 50 | }; 51 | 52 | context["when all promises fail"] = () => { 53 | before = () => { 54 | p1 = TestHelper.PromiseWithError("error 42", delay); 55 | p2 = TestHelper.PromiseWithError("error 43", delay * 2); 56 | p3 = TestHelper.PromiseWithError("error 44", delay * 3); 57 | promise = Promise.Any(p1, p2, p3); 58 | promise.Await(); 59 | }; 60 | 61 | it["fails"] = () => promise.state.should_be(PromiseState.Failed); 62 | it["has no result"] = () => promise.result.should_be_null(); 63 | it["has error"] = () => promise.error.should_not_be_null(); 64 | }; 65 | } 66 | } 67 | 68 | -------------------------------------------------------------------------------- /Tests/Tests/describe_Collect.cs: -------------------------------------------------------------------------------- 1 | using NSpec; 2 | using Promises; 3 | using System.Collections.Generic; 4 | 5 | class describe_Collect : nspec { 6 | 7 | const int delay = 5; 8 | 9 | void when_running_in_parallel_with_collect() { 10 | Promise p1 = null; 11 | Promise p2 = null; 12 | Promise promise = null; 13 | List eventProgresses = null; 14 | 15 | context["when running with a promise that fulfills and one that fails"] = () => { 16 | before = () => { 17 | eventProgresses = new List(); 18 | p1 = TestHelper.PromiseWithError("error 42", delay * 2); 19 | p2 = TestHelper.PromiseWithResult("42", delay); 20 | promise = Promise.Collect(p1, p2); 21 | promise.OnProgressed += eventProgresses.Add; 22 | promise.Await(); 23 | }; 24 | 25 | it["is fulfilled"] = () => promise.state.should_be(PromiseState.Fulfilled); 26 | it["has progressed 100%"] = () => promise.progress.should_be(1f); 27 | it["has result"] = () => promise.result.should_not_be_null(); 28 | it["has no error"] = () => promise.error.should_be_null(); 29 | it["has results at correct index"] = () => { 30 | (promise.result[0]).should_be_null(); 31 | (promise.result[1]).should_be("42"); 32 | }; 33 | 34 | it["calls progress"] = () => { 35 | eventProgresses.Count.should_be(2); 36 | eventProgresses[0].should_be(0.5f); 37 | eventProgresses[1].should_be(1f); 38 | }; 39 | 40 | it["has initial progress"] = () => { 41 | var deferred = new Deferred(); 42 | deferred.Progress(0.5f); 43 | p2 = TestHelper.PromiseWithResult("42", delay); 44 | var collect = Promise.Collect(deferred, p2); 45 | collect.progress.should_be(0.25f); 46 | deferred.Fulfill(null); 47 | collect.Await(); 48 | }; 49 | }; 50 | 51 | context["when all promises fail"] = () => { 52 | before = () => { 53 | eventProgresses = new List(); 54 | p1 = TestHelper.PromiseWithError("error 42", delay * 2); 55 | p2 = TestHelper.PromiseWithError("error 43", delay); 56 | promise = Promise.Collect(p1, p2); 57 | promise.OnProgressed += eventProgresses.Add; 58 | promise.Await(); 59 | }; 60 | 61 | it["progresses"] = () => { 62 | eventProgresses.Count.should_be(2); 63 | eventProgresses[0].should_be(0.5f); 64 | eventProgresses[1].should_be(1f); 65 | }; 66 | }; 67 | } 68 | } 69 | 70 | -------------------------------------------------------------------------------- /Tests/Tests/describe_Promise.cs: -------------------------------------------------------------------------------- 1 | using NSpec; 2 | using System; 3 | using Promises; 4 | using System.Threading; 5 | 6 | class describe_Promise : nspec { 7 | 8 | const int delay = 5; 9 | 10 | void when_running_an_expensive_action() { 11 | Promise promise = null; 12 | string eventResult = null; 13 | Exception eventError = null; 14 | float eventProgress = 0f; 15 | bool fulfilledCalled = false, failedCalled = false, progressCalled = false; 16 | 17 | before = () => { 18 | eventResult = null; 19 | eventError = null; 20 | eventProgress = -1f; 21 | fulfilledCalled = failedCalled = progressCalled = false; 22 | }; 23 | 24 | after = () => promise.Await(); 25 | 26 | context["before action finished"] = () => { 27 | 28 | before = () => { 29 | promise = TestHelper.PromiseWithResult("42", delay); 30 | promise.OnFulfilled += result => { 31 | eventResult = result; 32 | fulfilledCalled = true; 33 | }; 34 | promise.OnFailed += error => { 35 | eventError = error; 36 | failedCalled = true; 37 | }; 38 | promise.OnProgressed += progress => { 39 | eventProgress = progress; 40 | progressCalled = true; 41 | }; 42 | }; 43 | 44 | it["is unfulfilled"] = () => promise.state.should_be(PromiseState.Unfulfilled); 45 | it["has progressed 0%"] = () => promise.progress.should_be(0f); 46 | it["has no result"] = () => promise.result.should_be_null(); 47 | it["has no error"] = () => promise.error.should_be_null(); 48 | 49 | context["await"] = () => { 50 | it["blocks until finished"] = () => { 51 | promise.Await(); 52 | promise.state.should_be(PromiseState.Fulfilled); 53 | }; 54 | 55 | it["does nothing when promise already finished"] = () => { 56 | promise.Await(); 57 | promise.Await(); 58 | true.should_be_true(); 59 | }; 60 | 61 | it["returns promise"] = () => promise.Await().result.should_be("42"); 62 | }; 63 | 64 | context["events"] = () => { 65 | it["doesn't call OnFulfilled"] = () => fulfilledCalled.should_be_false(); 66 | it["doesn't call OnFail"] = () => failedCalled.should_be_false(); 67 | it["doesn't call OnProgress"] = () => progressCalled.should_be_false(); 68 | }; 69 | 70 | context["when action finished"] = () => { 71 | 72 | before = () => promise.Await(); 73 | 74 | it["is fulfilled"] = () => promise.state.should_be(PromiseState.Fulfilled); 75 | it["has progressed 100%"] = () => promise.progress.should_be(1f); 76 | it["has result"] = () => promise.result.should_be("42"); 77 | it["has no error"] = () => promise.error.should_be_null(); 78 | 79 | context["events"] = () => { 80 | it["calls OnFulfilled"] = () => eventResult.should_be("42"); 81 | it["calls OnFulfilled when adding callback"] = () => { 82 | string lateResult = null; 83 | promise.OnFulfilled += result => lateResult = result; 84 | lateResult.should_be("42"); 85 | }; 86 | it["doesn't call OnFailed"] = () => failedCalled.should_be_false(); 87 | it["doesn't call OnFailed when adding callback"] = () => { 88 | var called = false; 89 | promise.OnFailed += error => called = true; 90 | called.should_be_false(); 91 | }; 92 | it["calls OnProgress"] = () => eventProgress.should_be(1f); 93 | }; 94 | }; 95 | }; 96 | 97 | context["when action throws an exception"] = () => { 98 | 99 | before = () => { 100 | promise = TestHelper.PromiseWithError("error 42", delay); 101 | promise.OnFulfilled += result => { 102 | eventResult = result; 103 | fulfilledCalled = true; 104 | }; 105 | promise.OnFailed += error => { 106 | eventError = error; 107 | failedCalled = true; 108 | }; 109 | promise.OnProgressed += progress => { 110 | eventProgress = progress; 111 | eventProgress = progress; 112 | }; 113 | promise.Await(); 114 | }; 115 | 116 | it["failed"] = () => promise.state.should_be(PromiseState.Failed); 117 | it["has progressed 0%"] = () => promise.progress.should_be(0f); 118 | it["has no result"] = () => promise.result.should_be_null(); 119 | it["has error"] = () => promise.error.Message.should_be("error 42"); 120 | 121 | context["events"] = () => { 122 | it["doesn't call OnFulfilled"] = () => fulfilledCalled.should_be_false(); 123 | it["doesn't call OnFulfilled when adding callback"] = () => { 124 | var called = false; 125 | promise.OnFulfilled += result => called = true; 126 | called.should_be_false(); 127 | }; 128 | it["calls OnFailed"] = () => eventError.Message.should_be("error 42"); 129 | it["calls OnFailed when adding callback"] = () => { 130 | Exception lateError = null; 131 | promise.OnFailed += error => lateError = error; 132 | lateError.Message.should_be("error 42"); 133 | }; 134 | it["doesn't call OnProgress"] = () => progressCalled.should_be_false(); 135 | }; 136 | }; 137 | 138 | context["when creating a custom promise with Deferred"] = () => { 139 | Deferred deferred = null; 140 | int progressEventCalled = 0; 141 | 142 | before = () => { 143 | deferred = new Deferred(); 144 | progressEventCalled = 0; 145 | deferred.OnProgressed += progress => { 146 | eventProgress = progress; 147 | progressEventCalled++; 148 | }; 149 | }; 150 | 151 | it["progresses"] = () => { 152 | deferred.Progress(0.3f); 153 | deferred.Progress(0.6f); 154 | deferred.Progress(0.9f); 155 | deferred.Progress(1f); 156 | 157 | eventProgress.should_be(1f); 158 | deferred.promise.progress.should_be(1f); 159 | progressEventCalled.should_be(4); 160 | }; 161 | 162 | it["doesn't call OnProgressed when setting equal progress"] = () => { 163 | deferred.Progress(0.3f); 164 | deferred.Progress(0.3f); 165 | deferred.Progress(0.3f); 166 | deferred.Progress(0.6f); 167 | 168 | eventProgress.should_be(0.6f); 169 | deferred.promise.progress.should_be(0.6f); 170 | progressEventCalled.should_be(2); 171 | }; 172 | 173 | it["doesn't call OnProgressed when adding callback when progress is less than 100%"] = () => { 174 | deferred.Progress(0.3f); 175 | var called = false; 176 | deferred.OnProgressed += progress => called = true; 177 | called.should_be_false(); 178 | }; 179 | 180 | it["calls OnProgressed when adding callback when progress is 100%"] = () => { 181 | deferred.Progress(1f); 182 | var called = false; 183 | deferred.OnProgressed += progress => called = true; 184 | called.should_be_true(); 185 | }; 186 | }; 187 | 188 | context["wrap"] = () => { 189 | 190 | Promise wrapped = null; 191 | 192 | context["when wrapped promise fulfills"] = () => { 193 | before = () => { 194 | }; 195 | 196 | it["forwards fulfill"] = () => { 197 | promise = TestHelper.PromiseWithResult("42", delay); 198 | wrapped = promise.Wrap(); 199 | wrapped.Await(); 200 | wrapped.state.should_be(PromiseState.Fulfilled); 201 | }; 202 | 203 | it["forwards fail"] = () => { 204 | promise = TestHelper.PromiseWithError("error 42", delay); 205 | wrapped = promise.Wrap(); 206 | wrapped.Await(); 207 | wrapped.state.should_be(PromiseState.Failed); 208 | }; 209 | 210 | it["forwards progress"] = () => { 211 | var deferred = new Deferred(); 212 | wrapped = deferred.Wrap(); 213 | deferred.Progress(0.5f); 214 | wrapped.progress.should_be(0.5f); 215 | }; 216 | 217 | it["has initial progress"] = () => { 218 | var deferred = new Deferred(); 219 | deferred.Progress(0.5f); 220 | wrapped = deferred.Wrap(); 221 | wrapped.progress.should_be(0.5f); 222 | }; 223 | }; 224 | }; 225 | 226 | context["toString"] = () => { 227 | it["returns description of unfulfilled promise"] = () => { 228 | var deferred = new Deferred(); 229 | deferred.Progress(0.1234567890f); 230 | deferred.promise.ToString().should_be("[Promise: state = Unfulfilled, progress = 0,123]"); 231 | }; 232 | 233 | it["returns description of fulfilled promise"] = () => { 234 | promise = TestHelper.PromiseWithResult("42"); 235 | promise.Await(); 236 | promise.ToString().should_be("[Promise: state = Fulfilled, result = 42]"); 237 | }; 238 | 239 | it["returns description of failed promise"] = () => { 240 | promise = TestHelper.PromiseWithError("error 42"); 241 | promise.Await(); 242 | promise.ToString().should_be("[Promise: state = Failed, progress = 0, error = error 42]"); 243 | }; 244 | }; 245 | } 246 | } -------------------------------------------------------------------------------- /Tests/Tests/describe_Rescue.cs: -------------------------------------------------------------------------------- 1 | using NSpec; 2 | using System; 3 | using Promises; 4 | using System.Threading; 5 | 6 | class describe_Rescue : nspec { 7 | 8 | const int delay = 5; 9 | 10 | void when_using_rescue() { 11 | Promise promise = null; 12 | string eventResult = null; 13 | 14 | before = () => eventResult = null; 15 | after = () => promise.Await(); 16 | 17 | it["rescues failed promise"] = () => { 18 | promise = TestHelper.PromiseWithError("error 42", delay).Rescue(error => "rescue"); 19 | promise.OnFulfilled += result => eventResult = result; 20 | promise.Await(); 21 | promise.state.should_be(PromiseState.Fulfilled); 22 | promise.progress.should_be(1f); 23 | promise.result.should_be("rescue"); 24 | promise.error.should_be_null(); 25 | eventResult.should_be("rescue"); 26 | }; 27 | 28 | it["rescues already failed promise"] = () => { 29 | promise = TestHelper.PromiseWithError("error 42").Rescue(error => "rescue"); 30 | promise.OnFulfilled += result => eventResult = result; 31 | promise.Await(); 32 | promise.state.should_be(PromiseState.Fulfilled); 33 | promise.progress.should_be(1f); 34 | promise.result.should_be("rescue"); 35 | promise.error.should_be_null(); 36 | eventResult.should_be("rescue"); 37 | }; 38 | 39 | it["fulfills when no error"] = () => { 40 | promise = TestHelper.PromiseWithResult("42", delay).Rescue(error => "rescue"); 41 | promise.OnFulfilled += result => eventResult = result; 42 | promise.Await(); 43 | Thread.SpinWait(0); 44 | promise.state.should_be(PromiseState.Fulfilled); 45 | promise.progress.should_be(1f); 46 | promise.result.should_be("42"); 47 | promise.error.should_be_null(); 48 | eventResult.should_be("42"); 49 | }; 50 | 51 | context["progress"] = () => { 52 | Deferred deferred = null; 53 | var progressCalled = 0; 54 | var eventProgress = 0f; 55 | 56 | before = () => { 57 | eventProgress = 0f; 58 | progressCalled = 0; 59 | deferred = new Deferred(); 60 | deferred.Progress(0.1f); 61 | promise = deferred.Rescue(error => "43"); 62 | promise.OnProgressed += progress => { 63 | eventProgress = progress; 64 | progressCalled++; 65 | }; 66 | }; 67 | 68 | it["forwards progress"] = () => { 69 | deferred.Progress(0.3f); 70 | deferred.Progress(0.6f); 71 | deferred.Fulfill("42"); 72 | 73 | eventProgress.should_be(1f); 74 | promise.progress.should_be(1f); 75 | progressCalled.should_be(3); 76 | }; 77 | 78 | it["has initial progress"] = () => { 79 | promise.progress.should_be(0.1f); 80 | deferred.Fulfill("42"); 81 | }; 82 | }; 83 | 84 | it["calculates correct progress when concatenating with then"] = () => { 85 | Func p = result => { 86 | Thread.Sleep(delay); 87 | return "42"; 88 | }; 89 | Func r = error => { 90 | Thread.Sleep(delay); 91 | return "error"; 92 | }; 93 | 94 | promise = TestHelper.PromiseWithResult("42", delay) 95 | .Then(p) 96 | .Then(p) 97 | .Then(p).Rescue(r); 98 | 99 | 100 | int eventCalled = 0; 101 | var expectedProgresses = new [] { 0.25f, 0.5f, 0.75f, 1f }; 102 | promise.OnProgressed += progress => { 103 | progress.should_be(expectedProgresses[eventCalled]); 104 | eventCalled++; 105 | }; 106 | promise.Await(); 107 | eventCalled.should_be(expectedProgresses.Length); 108 | }; 109 | } 110 | } 111 | 112 | -------------------------------------------------------------------------------- /Tests/Tests/describe_Then.cs: -------------------------------------------------------------------------------- 1 | using NSpec; 2 | using Promises; 3 | using System; 4 | using System.Threading; 5 | 6 | class describe_Then : nspec { 7 | 8 | const int delay = 5; 9 | 10 | void when_concatenating_with_then() { 11 | Promise firstPromise = null; 12 | Promise thenPromise = null; 13 | 14 | after = () => { 15 | firstPromise.Await(); 16 | thenPromise.Await(); 17 | }; 18 | 19 | context["when first promise fulfilles"] = () => { 20 | 21 | before = () => { 22 | firstPromise = TestHelper.PromiseWithResult(42, delay); 23 | thenPromise = firstPromise.Then(result => { 24 | Thread.Sleep(delay); 25 | return result + "_then"; 26 | }); 27 | }; 28 | 29 | context["before first promise finished"] = () => { 30 | it["first promise is running"] = () => assertRunning(firstPromise, 0f); 31 | it["then promise is pending"] = () => assertPending(thenPromise); 32 | it["then promise waits"] = () => { 33 | thenPromise.Await(); 34 | assertFulfilled(firstPromise, 42); 35 | assertFulfilled(thenPromise, "42_then"); 36 | }; 37 | 38 | context["when first promise finished"] = () => { 39 | before = () => firstPromise.Await(); 40 | 41 | it["first promise is fulfilled"] = () => assertFulfilled(firstPromise, 42); 42 | it["then promise in running with correct progress"] = () => assertRunning(thenPromise, 0.5f); 43 | 44 | context["when then promise finished"] = () => { 45 | before = () => thenPromise.Await(); 46 | it["then promise is fulfilled"] = () => assertFulfilled(thenPromise, "42_then"); 47 | }; 48 | }; 49 | }; 50 | }; 51 | 52 | context["when first promise fails"] = () => { 53 | 54 | before = () => { 55 | firstPromise = TestHelper.PromiseWithError("error 42", delay); 56 | thenPromise = firstPromise.Then(result => { 57 | Thread.Sleep(delay); 58 | return result + "_then"; 59 | }); 60 | firstPromise.Await(); 61 | }; 62 | 63 | it["first promise failed"] = () => assertFailed(firstPromise, "error 42"); 64 | it["then promise failed"] = () => assertFailed(thenPromise, "error 42"); 65 | }; 66 | 67 | context["when putting it all together"] = () => { 68 | 69 | it["fulfills all promises and passes result"] = () => { 70 | var promise = Promise.WithAction(() => "1") 71 | .Then(result => result + "2") 72 | .Then(result => result + "3") 73 | .Then(result => result + "4"); 74 | 75 | var fulfilled = 0; 76 | promise.OnFulfilled += result => fulfilled++; 77 | promise.Await(); 78 | fulfilled.should_be(1); 79 | promise.result.should_be("1234"); 80 | }; 81 | 82 | it["forwards error"] = () => { 83 | var promise = TestHelper.PromiseWithError("error 42") 84 | .Then(result => result + "2") 85 | .Then(result => result + "3") 86 | .Then(result => result + "4"); 87 | 88 | var fulfilled = false; 89 | Exception eventError = null; 90 | promise.OnFulfilled += result => fulfilled = true; 91 | promise.OnFailed += error => eventError = error; 92 | promise.Await(); 93 | fulfilled.should_be_false(); 94 | eventError.Message.should_be("error 42"); 95 | promise.result.should_be_null(); 96 | promise.error.Message.should_be("error 42"); 97 | }; 98 | 99 | it["calculates correct progress"] = () => { 100 | var promise = Promise.WithAction(() => { 101 | Thread.Sleep(delay); 102 | return "1"; 103 | }).Then(result => result + "2") 104 | .Then(result => result + "3") 105 | .Then(result => { 106 | throw new Exception("error 42"); 107 | }); 108 | 109 | int eventCalled = 0; 110 | var expectedProgresses = new [] { 0.25f, 0.5f, 0.75, 1f }; 111 | promise.OnProgressed += progress => { 112 | progress.should_be(expectedProgresses[eventCalled]); 113 | eventCalled++; 114 | }; 115 | promise.Await(); 116 | eventCalled.should_be(expectedProgresses.Length - 1); 117 | }; 118 | 119 | it["has initial progress"] = () => { 120 | var deferred = new Deferred(); 121 | deferred.Progress(0.5f); 122 | var then = deferred.promise.Then(result => 0); 123 | then.progress.should_be(0.25f); 124 | deferred.Fulfill(null); 125 | then.Await(); 126 | }; 127 | 128 | it["calculates correct progress with custum progress"] = () => { 129 | var deferred1 = new Deferred(); 130 | deferred1.action = () => { 131 | Thread.Sleep(delay); 132 | var progress = 0f; 133 | while (progress < 1f) { 134 | progress += 0.25f; 135 | deferred1.Progress(progress); 136 | Thread.Sleep(delay); 137 | } 138 | return 0; 139 | }; 140 | 141 | var deferred2 = new Deferred(); 142 | deferred2.action = () => { 143 | var progress = 0f; 144 | while (progress < 1f) { 145 | progress += 0.25f; 146 | deferred2.Progress(progress); 147 | Thread.Sleep(delay); 148 | } 149 | return 0; 150 | }; 151 | 152 | int eventCalled = 0; 153 | var expectedProgresses = new [] { 154 | 0.125f, 0.25f, 0.375, 0.5f, 155 | 0.625f, 0.75f, 0.875f, 1f, 156 | }; 157 | 158 | var promise = deferred1.RunAsync().Then(deferred2); 159 | promise.OnProgressed += progress => { 160 | progress.should_be(expectedProgresses[eventCalled]); 161 | eventCalled++; 162 | }; 163 | promise.Await(); 164 | eventCalled.should_be(expectedProgresses.Length); 165 | }; 166 | }; 167 | } 168 | 169 | void assertRunning(Promise p, float progress) { 170 | p.state.should_be(PromiseState.Unfulfilled); 171 | p.error.should_be_null(); 172 | p.progress.should_be(progress); 173 | 174 | if (p.result is int) 175 | p.result.should_be(0); 176 | else 177 | ((object)p.result).should_be_null(); 178 | } 179 | 180 | void assertPending(Promise p) { 181 | p.state.should_be(PromiseState.Unfulfilled); 182 | p.error.should_be_null(); 183 | p.progress.should_be(0f); 184 | 185 | if (p.result is int) 186 | p.result.should_be(0); 187 | else 188 | ((object)p.result).should_be_null(); 189 | } 190 | 191 | void assertFulfilled(Promise p, TResult result) { 192 | p.state.should_be(PromiseState.Fulfilled); 193 | p.error.should_be_null(); 194 | p.progress.should_be(1f); 195 | p.result.should_be(result); 196 | } 197 | 198 | void assertFailed(Promise p, string errorMessage) { 199 | p.state.should_be(PromiseState.Failed); 200 | p.error.should_not_be_null(); 201 | p.error.Message.should_be(errorMessage); 202 | 203 | if (p.result is int) 204 | p.result.should_be(0); 205 | else 206 | ((object)p.result).should_be_null(); 207 | } 208 | } 209 | 210 | -------------------------------------------------------------------------------- /runTests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | xbuild Tests/Tests.sln /verbosity:minimal 3 | if [ $? = 0 ] 4 | then 5 | mono Tests/Libraries/nspec/NSpecRunner.exe Tests/bin/Debug/Tests.dll 6 | else 7 | echo "ERROR: Could not compile!" 8 | exit 1 9 | fi 10 | --------------------------------------------------------------------------------