Ejemplo n.º 1
0
        public static ThreadContext CreateGenerator(ThreadFunc code, params object[] kwargs)
        {
            object[] args     = ParseKwargs(kwargs, new string[] { "capacity" }, 1);
            var      capacity = Convert.ToInt32(args[0]);
            var      context  = new GeneratorThreadContext(capacity);

            ThreadFunc wrapper = () =>
            {
                object val = code();
                context.YieldBreak();
                return(val);
            };

            return(CreateTaskWithContext(wrapper, context, true));
        }
Ejemplo n.º 2
0
        public static object CreateGenerator(ThreadFunc code, params object[] kwargs)
        {
            object[] args = ParseKwargs(kwargs, new string[] { "capacity" }, 1);
            var capacity = Convert.ToInt32(args[0]);
            var context = new GeneratorThreadContext(capacity);

            ThreadFunc wrapper = () =>
            {
                object val = code();
                context.YieldBreak();
                return val;
            };

            return CreateTaskWithContext(wrapper, context, true);
        }