31 lines
958 B
C#
31 lines
958 B
C#
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using MongoDB.Driver;
|
|
|
|
namespace xDataService.Mongo {
|
|
public class XMongoAsyncCursor<T> : IAsyncCursor<T> {
|
|
public IEnumerable<T> Current { get; }
|
|
private IEnumerator<T> CurrentEnumerator { get; }
|
|
|
|
public XMongoAsyncCursor (IEnumerable<T> source) {
|
|
this.Current = source;
|
|
this.CurrentEnumerator = source.GetEnumerator ();
|
|
}
|
|
|
|
public void Dispose () {
|
|
CurrentEnumerator.Dispose ();
|
|
}
|
|
|
|
public bool MoveNext (CancellationToken cancellationToken = default) {
|
|
return CurrentEnumerator.MoveNext ();
|
|
}
|
|
|
|
public Task<bool> MoveNextAsync (CancellationToken cancellationToken = default) {
|
|
return Task.Run (
|
|
() => CurrentEnumerator.MoveNext (),
|
|
cancellationToken : cancellationToken
|
|
);
|
|
}
|
|
}
|
|
} |