1111
1212namespace NiL . JS . BaseLibrary
1313{
14- public enum PromiseState
15- {
16- Pending ,
17- Fulfilled ,
18- Rejected
19- }
20-
21- public sealed class Promise
14+ public sealed class Promise : IPromiseLike
2215 {
2316 private Task _innerTask ;
2417 private Function _callback ;
@@ -177,20 +170,20 @@ private void callbackInvoke()
177170 _outerTask . SetResult ( JSValue . undefined ) ;
178171 }
179172
180- public static Promise resolve ( JSValue data )
173+ public static IPromiseLike resolve ( JSValue data )
181174 {
182175 return new Promise ( fromResult ( data ) ) ;
183176 }
184177
185- public static Promise race ( IIterable promises )
178+ public static IPromiseLike race ( IIterable promises )
186179 {
187180 if ( promises == null )
188181 return new Promise ( fromException ( new JSException ( new TypeError ( "Invalid argruments for Promise.race(...)" ) ) ) ) ;
189182
190183 return new Promise ( whenAny ( promises . AsEnumerable ( ) . Select ( convertToTask ) . ToArray ( ) ) ) ;
191184 }
192185
193- public static Promise all ( IIterable promises )
186+ public static IPromiseLike all ( IIterable promises )
194187 {
195188 if ( promises == null )
196189 return new Promise ( fromException ( new JSException ( new TypeError ( "Invalid argruments for Promise.all(...)" ) ) ) ) ;
@@ -203,20 +196,20 @@ private static Task<JSValue> convertToTask(JSValue arg)
203196 return ( arg . Value as Promise ) ? . Task ?? fromResult ( arg ) ;
204197 }
205198
206- public Promise @catch ( Function onRejection )
199+ public IPromiseLike @catch ( Function onRejection )
207200 {
208201 return then ( null , onRejection ) ;
209202 }
210203
211- public Promise then ( Function onFulfilment , Function onRejection )
204+ public IPromiseLike then ( Function onFulfilment , Function onRejection )
212205 {
213206 return then (
214207 onFulfilment == null ? null as Func < JSValue , JSValue > : value => onFulfilment . Call ( JSValue . undefined , new Arguments { value } ) ,
215208 onRejection == null ? null as Func < JSValue , JSValue > : value => onRejection . Call ( JSValue . undefined , new Arguments { value } ) ) ;
216209 }
217210
218211 [ Hidden ]
219- public Promise then ( Func < JSValue , JSValue > onFulfilment , Func < JSValue , JSValue > onRejection )
212+ public IPromiseLike then ( Func < JSValue , JSValue > onFulfilment , Func < JSValue , JSValue > onRejection )
220213 {
221214 if ( onFulfilment == null && onRejection == null )
222215 return resolve ( JSValue . undefined ) ;
0 commit comments