FutureGetCluster() public static method

public static FutureGetCluster ( FutureHandle future, ClusterHandle &cluster ) : FdbError
future FutureHandle
cluster ClusterHandle
return FdbError
コード例 #1
0
        private static async ValueTask <IFdbDatabaseHandler> CreateDatabaseLegacyAsync(string?clusterFile, CancellationToken ct)
        {
            // In legacy API versions, you first had to create "cluster" handle and then obtain a database handle that that cluster.
            // The API is async, but the future always completed inline...

            ClusterHandle? cluster  = null;
            DatabaseHandle?database = null;

            try
            {
                cluster = await FdbFuture.CreateTaskFromHandle(
                    FdbNative.CreateCluster(clusterFile),
                    h =>
                {
                    var err = FdbNative.FutureGetCluster(h, out var handle);
                    if (Fdb.Failed(err))
                    {
                        throw Fdb.MapToException(err) !;
                    }

                    return(handle);
                },
                    ct).ConfigureAwait(false);

                database = await FdbFuture.CreateTaskFromHandle(
                    FdbNative.ClusterCreateDatabase(cluster, "DB"),
                    h =>
                {
                    var err = FdbNative.FutureGetDatabase(h, out var handle);
                    if (Fdb.Failed(err))
                    {
                        throw Fdb.MapToException(err) !;
                    }

                    return(handle);
                },
                    ct).ConfigureAwait(false);

                return(new FdbNativeDatabase(database, clusterFile, cluster));
            }
            catch (Exception)
            {
                database?.Dispose();
                cluster?.Dispose();
                throw;
            }
        }
コード例 #2
0
        public static Task <IFdbClusterHandler> CreateClusterAsync(string clusterFile, CancellationToken ct)
        {
            var future = FdbNative.CreateCluster(clusterFile);

            return(FdbFuture.CreateTaskFromHandle(future,
                                                  (h) =>
            {
                var err = FdbNative.FutureGetCluster(h, out ClusterHandle cluster);
                if (err != FdbError.Success)
                {
                    cluster.Dispose();
                    throw Fdb.MapToException(err);
                }
                var handler = new FdbNativeCluster(cluster);
                return (IFdbClusterHandler)handler;
            },
                                                  ct
                                                  ));
        }