protected IEnumerator <object> WriteLotsOfValuesInBatch(Tangle <int> tangle, int numIterations, int direction) { int batchSize = 256; Batch <int> batch = null; if (direction > 0) { for (int i = 0; i < numIterations; i++) { if (batch == null) { batch = Tangle.CreateBatch(batchSize); } batch.Add(i, i); if (batch.Count == batchSize) { yield return(batch.Execute()); batch = null; } } } else { for (int i = numIterations - 1; i >= 0; i--) { if (batch == null) { batch = Tangle.CreateBatch(batchSize); } batch.Add(i, i); if (batch.Count == batchSize) { yield return(batch.Execute()); batch = null; } } } if (batch != null) { yield return(batch.Execute()); } }