Update Workflow instance variables from Promise.thenApply

Is it permissible to update Workflow instance variables in a Function provided to Promise.thenApply as in the example below?

private val count: Long = 0
// ...

val promises = items.map { item ->
  Async.function(activities::doSomething, item).thenApply { result -> count += result }
}

Promise.allOf(promises).get() // wait for all Promises to complete.

The idea is to update the Workflow state immediately when an invocation of the doSomething activity method completes to provide more “realtime” data from a Workflow query method. The alternative here would be to wait for all Promises to complete and then sum the results and update the Workflow. However, the objective is to update the Workflow state as each activity invocation completes. There can be a large variance in runtime between the activity invocations as the runtime is dependant on the input.
This code works but I wondering if it’s not considered best practice or is susceptible to race conditions.

This works is fine and is non susceptible to race conditions.

Another alternative would be using Promise.anyOf in a loop.