3

I implemented Azure function.

I have next case:

  1. When something uploaded to blob (Input Blob is trigger)
  2. Process logic
  3. Save something to output blob (Output as return value)
  4. Save something else to dynamo db collection (Output parameter)
  5. Save something else to another dynamo db collection (Output parameter)

    [FunctionName("myFunction")]
    [return: Blob("images-text-out/{name}.txt")]
    public static string Run([BlobTrigger("samples-workitems/{name}", Connection = "StorageConnection")]Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob myBlob,
         string name,
         string blobTrigger,
         [CosmosDB(
            databaseName: "my-db-cosmos",
            collectionName: "CollectionA",
            ConnectionStringSetting = "CosmosDBConnection")] out dynamic processedFirst,
         [CosmosDB(
            databaseName: "my-db-cosmos",
            collectionName: "CollectionB",
            ConnectionStringSetting = "CosmosDBConnection")] out dynamic processedSecond,
         ILogger log,
         ExecutionContext context)
    {
        // . . .
        myBlob.DownloadToStreamAsync(memoryStream).Wait();
        // . . .
    }
    

This is working fine. Problem is just that I cannot use advantage of async calls. It is clear why, because method with output parameter cannot be async methods.

How to implement azure function with multiple outputs by using advantage of async calls?

Thank you

1 Answer 1

7

We could use IAsyncCollector in async method.

Use the return value only if a successful function execution always results in a return value to pass to the output binding. Otherwise, use ICollector or IAsyncCollector

For example, change out dynamic processedSecond to IAsyncCollector<dynamic> processedFirst and use await processedFirst.AddAsync(someObject); later.

See the example of CosmosDB output.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.