How to use the apify-shared/utilities.delayPromise function in apify-shared

To help you get started, we’ve selected a few apify-shared examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apifytech / apify-js / test / request_list.js View on Github external
.returns(Promise.resolve());
        Apify.events.emit(ACTOR_EVENT_NAMES_EX.PERSIST_STATE);
        await delayPromise(1);
        expect(requestList.isStatePersisted).to.be.eql(true);

        // Do some other changes and persist it again.
        const request2 = await requestList.fetchNextRequest();
        expect(requestList.isStatePersisted).to.be.eql(false);
        await requestList.markRequestHandled(request2);
        expect(requestList.isStatePersisted).to.be.eql(false);
        mock.expects('setValue')
            .once()
            .withArgs(PERSIST_STATE_KEY, requestList.getState())
            .returns(Promise.resolve());
        Apify.events.emit(ACTOR_EVENT_NAMES_EX.PERSIST_STATE);
        await delayPromise(1);
        expect(requestList.isStatePersisted).to.be.eql(true);

        // Reclaim event doesn't change the state.
        await requestList.reclaimRequest(request1);
        expect(requestList.isStatePersisted).to.be.eql(true);

        // Now initiate new request list from saved state and check that it's same as state
        // of original request list.
        mock.expects('getValue')
            .once()
            .withArgs(PERSIST_STATE_KEY)
            .returns(Promise.resolve(requestList.getState()));
        const requestList2 = new Apify.RequestList(opts);
        await requestList2.initialize();
        expect(requestList2.getState()).to.be.eql(requestList.getState());
github apifytech / apify-js / test / autoscaling / autoscaled_pool.js View on Github external
it('should not handle tasks added after isFinishedFunction returned true', async () => {
        const isFinished = async () => count > 10;
        let count = 0;

        // Run the pool and close it after 3s.
        const pool = new AutoscaledPool({
            minConcurrency: 3,
            runTaskFunction: async () => delayPromise(1).then(() => { count++; }),
            isFinishedFunction: async () => isFinished(),
            isTaskReadyFunction: async () => !await isFinished(),
        });
        pool.maybeRunIntervalMillis = 5;

        await pool.run();
        await delayPromise(10);
        // Check finished tasks.
        expect(count).to.be.within(11, 13);
    });
github apifytech / apify-js / test / events.js View on Github external
Apify.main(async () => {
            await delayPromise(10); // Here must be short sleep to get following line to later tick
            expect(isWsConnected).to.be.eql(true);
            Apify.events.on('name-1', data => eventsReceived.push(data));
            await delayPromise(1000);
        });
github apifytech / apify-js / test / events.js View on Github external
Apify.main(async () => {
            await delayPromise(10); // Here must be short sleep to get following line to later tick
            expect(isWsConnected).to.be.eql(true);
            Apify.events.on('name-1', data => eventsReceived.push(data));
            await delayPromise(1000);
        });
github apifytech / apify-js / test / crawlers / basic_crawler.js View on Github external
handleRequestFunction: async () => {
                await delayPromise(1);
                count++;
            },
            maxRequestsPerCrawl: 40,
github apifytech / apify-js / test / actor.js View on Github external
userFunc: async () => {
                await delayPromise(20);
                throw new Error('Test exception II');
            },
            exitCode: 91,
github apifytech / apify-js / test / crawlers / cheerio_crawler.js View on Github external
cheerioCrawler._requestFunction = async () => {
                await delayPromise(300);
                return 'Body';
            };
github apifytech / apify-js / test / autoscaling / autoscaled_pool.js View on Github external
runTaskFunction: async () => {
                await delayPromise(1);
                if (counter === 10) { isTaskReady = false; setTimeout(() => { isTaskReady = true; }, 10); }
                if (counter === 19) { isTaskReady = false; isFinished = true; }
                counter++;
                finished.push(Date.now());
            },
            isFinishedFunction: async () => isFinished,
github apifytech / apify-js / test / crawlers / cheerio_crawler.js View on Github external
const handlePageFunction = async ({ request }) => {
                await delayPromise(3000);
                processed.push(request);
            };
github apifytech / apify-js / test / autoscaling / autoscaled_pool.js View on Github external
runTaskFunction: async () => {
                started = true;
                await delayPromise(100);
                completed = true;
            },