CqlSharp.CqlConnection.OpenAsync C# (CSharp) Метод

OpenAsync() публичный Метод

This is the asynchronous version of M:System.Data.Common.DbConnection.Open. The cancellation token can optionally be honored.The default implementation invokes the synchronous call and returns a completed task. The default implementation will return a cancelled task if passed an already cancelled cancellationToken. Exceptions thrown by Open will be communicated via the returned Task Exception property.Do not invoke other methods and properties of the DbConnection object until the returned Task is complete.
Connection must be closed before it is opened
public OpenAsync ( CancellationToken cancellationToken ) : Task
cancellationToken System.Threading.CancellationToken The cancellation instruction.
Результат Task
        public override Task OpenAsync(CancellationToken cancellationToken)
        {
            if(State != ConnectionState.Closed)
                throw new InvalidOperationException("Connection must be closed before it is opened");

            return OpenAsyncInternal(cancellationToken);
        }

Usage Example

Пример #1
0
		public async Task<List<string>> Get(string appId, string itemId, string relation, string userId)
		{
			using (var conn = new CqlConnection(_connString))
			{
				await conn.OpenAsync().ConfigureAwait(false);
				var query = string.Format(
					System.Globalization.CultureInfo.InvariantCulture,
					"select values from negrapi.relations where app_id = '{0}' and item_id='{1}' and relation='{2}';",
					appId,
					GetKey(itemId, userId),
					relation);

				var cmd = new CqlCommand(
					conn,
					query,
					CqlConsistency.One);

				var result = await cmd.ExecuteScalarAsync().ConfigureAwait(false) as string;

				if (string.IsNullOrEmpty(result))
				{
					return null;
				}

				var list = JsonConvert.DeserializeObject<List<RecommendationsDataValue>>(result);
				return list
					.Select(i => i.ItemId)
					.ToList();
			}
		}
All Usage Examples Of CqlSharp.CqlConnection::OpenAsync