Ejemplo n.º 1
0
        private static void NativeCancelCb(IntPtr data, IntPtr dead)
        {
            if (data == IntPtr.Zero)
            {
                return;
            }

            GCHandle handle = GCHandle.FromIntPtr(data);
            CancelCb cb     = handle.Target as CancelCb;

            if (cb != null)
            {
                cb();
            }
            else
            {
                Eina.Log.Info("Null promise CancelCb found");
            }
            handle.Free();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new Promise with the given callback.
        ///
        /// Currently, creating a promise directly uses the Main Loop scheduler the source of notifications (i.e. the
        /// future callbacks will be called mainly from a loop iteration).
        /// </summary>
        public Promise(CancelCb cancelCb = null)
        {
            Efl.Loop loop = Efl.App.AppMain;

            // Should we be able to pass different schedulers?
            IntPtr scheduler = efl_loop_future_scheduler_get(loop.NativeHandle);

            IntPtr cb_data = IntPtr.Zero;

            // A safety clean callback to mark this wrapper as invalid
            CancelCb safetyCb = () => {
                Handle = IntPtr.Zero;
                if (cancelCb != null)
                {
                    cancelCb();
                }
            };

            CleanupHandle = GCHandle.Alloc(safetyCb);
            cb_data       = GCHandle.ToIntPtr(CleanupHandle);

            this.Handle = eina_promise_new(scheduler, NativeCancelCb, cb_data);
        }