Пример #1
0
 /// <summary>Runs a transactional lambda function against this database, inside a read-write transaction context, with retry logic.</summary>
 /// <param name="handler">Asynchronous lambda function that is passed a new read-write transaction on each retry. The result of the task will also be the result of the transactional.</param>
 /// <param name="success">Will be called at most once, and only if the transaction commits successfully. Any exception or crash that happens right after the commit may cause this callback not NOT be called, even if the transaction has committed!</param>
 /// <param name="ct">Optional cancellation token that will be passed to the transaction context, and that can also be used to abort the retry loop.</param>
 public Task <TResult> ReadWriteAsync <TIntermediate, TResult>([InstantHandle] Func <IFdbTransaction, Task <TIntermediate> > handler, [InstantHandle] Func <IFdbTransaction, TIntermediate, Task <TResult> > success, CancellationToken ct)
 {
     return(FdbOperationContext.RunWriteWithResultAsync <TIntermediate, TResult>(this, handler, success, ct));
 }
Пример #2
0
 /// <summary>Runs a transactional lambda function against this database, inside a read-write transaction context, with retry logic.</summary>
 /// <param name="handler">Asynchronous lambda function that is passed a new read-write transaction on each retry. The result of the task will also be the result of the transactional.</param>
 /// <param name="ct">Optional cancellation token that will be passed to the transaction context, and that can also be used to abort the retry loop.</param>
 public Task <TResult> ReadWriteAsync <TResult>([InstantHandle] Func <IFdbTransaction, TResult> handler, CancellationToken ct)
 {
     return(FdbOperationContext.RunWriteWithResultAsync <TResult>(this, handler, ct));
 }
Пример #3
0
 /// <summary>Runs a transactional lambda function against this database, inside a read-write transaction context, with retry logic.</summary>
 /// <param name="state">State that will be passed back to the <paramref name="handler"/></param>
 /// <param name="handler">Asynchronous lambda function that is passed a new read-write transaction on each retry. The result of the task will also be the result of the transactional.</param>
 /// <param name="ct">Optional cancellation token that will be passed to the transaction context, and that can also be used to abort the retry loop.</param>
 public Task <TResult> ReadWriteAsync <TState, TResult>(TState state, [InstantHandle] Func <IFdbTransaction, TState, Task <TResult> > handler, CancellationToken ct)
 {
     Contract.NotNull(handler, nameof(handler));
     return(FdbOperationContext.RunWriteWithResultAsync <TResult>(this, (tr) => handler(tr, state), ct));
 }
Пример #4
0
 /// <summary>Runs a transactional lambda function against this database, inside a write-only transaction context, with retry logic.</summary>
 /// <param name="state">State that will be passed back to the <paramref name="handler"/></param>
 /// <param name="handler">Lambda function that is passed a new read-write transaction on each retry. It should only call non-async methods, such as Set, Clear or any atomic operation.</param>
 /// <param name="ct">Optional cancellation token that will be passed to the transaction context, and that can also be used to abort the retry loop.</param>
 public Task WriteAsync <TState>(TState state, [InstantHandle] Action <IFdbTransaction, TState> handler, CancellationToken ct)
 {
     return(FdbOperationContext.RunWriteAsync(this, (tr) => handler(tr, state), ct));
 }
Пример #5
0
 /// <summary>EXPERIMENTAL</summary>
 public Task ReadWriteAsync([InstantHandle] Func <IFdbTransaction, Task> handler, [InstantHandle] Action <IFdbTransaction> success, CancellationToken ct)
 {
     return(FdbOperationContext.RunWriteAsync(this, handler, success, ct));
 }
Пример #6
0
 /// <summary>Runs a transactional lambda function against this database, inside a write-only transaction context, with retry logic.</summary>
 /// <param name="handler">Lambda function that is passed a new read-write transaction on each retry. It should only call non-async methods, such as Set, Clear or any atomic operation.</param>
 /// <param name="ct">Optional cancellation token that will be passed to the transaction context, and that can also be used to abort the retry loop.</param>
 public Task WriteAsync([InstantHandle] Action <IFdbTransaction> handler, CancellationToken ct)
 {
     return(FdbOperationContext.RunWriteAsync(this, handler, ct));
 }
Пример #7
0
 public Task <TResult> ReadAsync <TResult>([InstantHandle] Func <IFdbReadOnlyTransaction, Task <TResult> > handler, [InstantHandle] Action <IFdbReadOnlyTransaction, TResult> success, CancellationToken ct)
 {
     return(FdbOperationContext.RunReadWithResultAsync <TResult>(this, handler, success, ct));
 }
Пример #8
0
 /// <summary>Runs a transactional lambda function against this database, inside a read-only transaction context, with retry logic.</summary>
 /// <param name="state">State that will be passed back to the <paramref name="handler"/></param>
 /// <param name="handler">Asynchronous lambda function that is passed a new read-only transaction on each retry. The result of the task will also be the result of the transactional.</param>
 /// <param name="ct">Optional cancellation token that will be passed to the transaction context, and that can also be used to abort the retry loop.</param>
 public Task <TResult> ReadAsync <TState, TResult>(TState state, Func <IFdbReadOnlyTransaction, TState, Task <TResult> > handler, CancellationToken ct)
 {
     return(FdbOperationContext.RunReadWithResultAsync <TResult>(this, (tr) => handler(tr, state), ct));
 }
Пример #9
0
        //NOTE: other bindings use different names or concept for transactionals, and some also support ReadOnly vs ReadWrite transaction
        // - Python uses the @transactional decorator with first arg called db_or_trans
        // - JAVA uses db.run() and db.runAsync(), but does not have a method for read-only transactions
        // - Ruby uses db.transact do |tr|
        // - Go uses db.Transact(...) and db.ReadTransact(...)
        // - NodeJS uses fdb.doTransaction(function(...) { ... })

        // Conventions:
        // - ReadAsync() => read-only
        // - WriteAsync() => write-only
        // - ReadWriteAsync() => read/write

        #region IFdbReadOnlyTransactional methods...

        /// <summary>Runs a transactional lambda function against this database, inside a read-only transaction context, with retry logic.</summary>
        /// <param name="handler">Asynchronous lambda function that is passed a new read-only transaction on each retry. The result of the task will also be the result of the transactional.</param>
        /// <param name="ct">Optional cancellation token that will be passed to the transaction context, and that can also be used to abort the retry loop.</param>
        public Task <TResult> ReadAsync <TResult>(Func <IFdbReadOnlyTransaction, Task <TResult> > handler, CancellationToken ct)
        {
            return(FdbOperationContext.RunReadWithResultAsync <TResult>(this, handler, ct));
        }
Пример #10
0
 /// <summary>Start a new transaction on this database</summary>
 /// <param name="mode">Mode of the new transaction (read-only, read-write, ...)</param>
 /// <param name="ct">Optional cancellation token that can abort all pending async operations started by this transaction.</param>
 /// <param name="context">If not null, attach the new transaction to an existing context.</param>
 /// <returns>New transaction instance that can read from or write to the database.</returns>
 /// <remarks>You MUST call Dispose() on the transaction when you are done with it. You SHOULD wrap it in a 'using' statement to ensure that it is disposed in all cases.</remarks>
 /// <example>
 /// using(var tr = db.BeginTransaction(CancellationToken.None))
 /// {
 ///		tr.Set(Slice.FromString("Hello"), Slice.FromString("World"));
 ///		tr.Clear(Slice.FromString("OldValue"));
 ///		await tr.CommitAsync();
 /// }</example>
 public IFdbTransaction BeginTransaction(FdbTransactionMode mode, CancellationToken ct, FdbOperationContext context = null)
 {
     ct.ThrowIfCancellationRequested();
     if (context == null)
     {
         context = new FdbOperationContext(this, mode, ct);
     }
     return(CreateNewTransaction(context));
 }