How to run a long running job with ECS?

I have seen information talking about long running jobs in ECS, but have found no example. Just trying to not return the jobHandle from onUpdate does not work.

Here is an example:

using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;

public class TestAsync2System : JobComponentSystem {
    int count = 0;
    JobHandle jobHandle;

    protected override JobHandle OnUpdate(JobHandle inputDependencies) {
        if (count == 0) {
            UnityEngine.Debug.Log("inc count: "+count);
        } else {
            if (jobHandle.IsCompleted) {
                UnityEngine.Debug.Log("completed: "+count);
                count = 0;
        return inputDependencies;

    private void schedule(JobHandle inputDependencies) {
        NativeArray<bool> result = new NativeArray<bool>(1, Allocator.Persistent);
        result[0] = false;
        jobHandle = Job.WithDeallocateOnJobCompletion(result).WithCode(() => {
            for (long i = 0; i < 100000000; i++) {}
            result[0] = true;

I’m not sure if that NativeArray should be necessary, but without it, it gives a burst error (but maybe that is a bug that will be resolved later).

More details here: