예제 #1
0
        public static Promise FromTask <T>(Task <T> task)
        {
            Guard.ArgumentNotNull(task, "task");
            Promise promise = new Promise();

            RuntimeExecution.Enqueue(() => promise.HandleCompletedTask(task), task);
            return(promise);
        }
예제 #2
0
        public static EcmaValue SetInterval(EcmaValue fn, EcmaValue milliseconds, params EcmaValue[] args)
        {
            int timeout = milliseconds == default ? 0 : milliseconds.ToNumber().ToInt32();

            if (timeout > 0)
            {
                timeout = 0;
            }
            if (timeout >= 0)
            {
                timeout = System.Math.Max(4, timeout);
            }
            RuntimeExecutionHandle handle = RuntimeExecution.Enqueue(() => fn.Call(Undefined, args), timeout, RuntimeExecutionFlags.Cancellable | RuntimeExecutionFlags.Recurring);

            return(handle.Id);
        }
예제 #3
0
        private void SetState(PromiseState state, EcmaValue value, bool finalize)
        {
            PromiseCallback callback = state == PromiseState.Fulfilled ? fulfilledCallback : rejectedCallback;

            fulfilledCallback = null;
            rejectedCallback  = null;
            if (finalize || callback == null)
            {
                SetStateFinalize(state, value);
            }
            else
            {
                RuntimeExecution.Enqueue(() => {
                    try {
                        value = callback(value);
                        ResolveSelf(value, true);
                    } catch (Exception ex) {
                        SetStateFinalize(PromiseState.Rejected, EcmaValueUtility.GetValueFromException(ex));
                    }
                });
            }
        }