Async programming and Azure functions
Async programming and Azure functions
Async programming and Azure functions
Re: Async programming and Azure functions
You can make the function async:
```
public static async Task Run(
[ServiceBusTrigger("topicname", "subname", AccessRights.Manage, Connection = "TopicConnection")]string message,
TraceWriter log)
{
try
{
log.Info($"C# ServiceBus topic trigger function processed message: {message}");
await PushToDb(message, log);
}
catch(Exception ex)
{
log.Info($"Exception found {ex.Message}");
}
}
```
The Functions runtime allows you to make your function async and return a Task.
In this case we can just await the call so we can handle exceptions normally.
```
public static async Task Run(
[ServiceBusTrigger("topicname", "subname", AccessRights.Manage, Connection = "TopicConnection")]string message,
TraceWriter log)
{
try
{
log.Info($"C# ServiceBus topic trigger function processed message: {message}");
await PushToDb(message, log);
}
catch(Exception ex)
{
log.Info($"Exception found {ex.Message}");
}
}
```
The Functions runtime allows you to make your function async and return a Task.
In this case we can just await the call so we can handle exceptions normally.