Skip to content

Instantly share code, notes, and snippets.

@eral
Last active August 29, 2015 14:13
Show Gist options
  • Save eral/d2ad96c34466f7d77b4d to your computer and use it in GitHub Desktop.
Save eral/d2ad96c34466f7d77b4d to your computer and use it in GitHub Desktop.
Cancelable LINQ
// Created by ERAL
// This is free and unencumbered software released into the public domain.
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using System.Linq;
public class CancelableLinq {
[MenuItem("Test/Cancelable LINQ")]
public static void Test() {
var enumerable = CreateEnumerable();
var progressDelta = 1.0f / enumerable.Count();
var logs = enumerable.TakeWhile((x,i)=>!EditorUtility.DisplayCancelableProgressBar("Cancelable LINQ", x.ToString(), i * progressDelta))
.Select(x=>string.Format("{0}^2 == {1}", x, x * x))
.ToArray();
EditorUtility.ClearProgressBar();
DisplayLogs(logs);
}
private static IEnumerable<int> CreateEnumerable() {
return Enumerable.Range(0, 1000);
}
private static void DisplayLogs(string[] logs) {
foreach (var log in logs) {
Debug.Log(log);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment