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)); }
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); }