Allocating "between" two jobs that are dependent on each other?

I’ve got the following scenario:

Job A runs, does some calculations, part of which is calculating some value n.
Once it’s done, I allocate a native hash set with capacity n, pass it in Job B and schedule Job B.

Is there some way to do this using job dependencies? Currently I have to wait for Job A to finish, and I can’t see a way of getting around this without using async/threading, which feels like a shame.

Allocate the NativeHashSet beforehand then just have a IJob schedule between them that resizes the capacity if required

[BurstCompile]
public CapacityJob : IJob
{
    public NativeHashSet<int> HashSet;
    public NativeList<int> List;
  
    public void Execute()
    {
        if (HashSet.Capacity < List.Length)
        {
            HashSet.Capacity = List.Length;
        }
    }
}

Works just as well in Job.WithCode

1 Like

Thanks, I didn’t realize you could resize it/change the capacity, when you can’t allocate a new one, pretty surprising.