How to use launchWorker method in ava

Best JavaScript code snippet using ava

fast-async-queue.js

Source:fast-async-queue.js Github

copy

Full Screen

1// Queue that doesn't have the buggy drain behavior of async/queue2// And it doesn't support promises on `.push()`3// If you need promise handling when pushing objects, just create them yourself4// and resolve them in the job5module.exports = function fastAsyncQueue (opts) {6 const queue = []7 const unusedWorkers = []8 const processFn = opts.process9 const catchFn = opts.catch10 const context = opts.context11 const concurrency = opts.concurrency || 1012 if (typeof concurrency !== 'number') {13 throw new Error('fastAsyncQueue: opts.concurrency must be a number')14 }15 if (typeof processFn !== 'function') {16 throw new Error('fastAsyncQueue: opts.process must be a function')17 }18 if (catchFn && typeof catchFn !== 'function') {19 throw new Error('fastAsyncQueue: opts.catch must be a function')20 }21 let stopped22 let drainResolve23 let drainLowWaterMark24 let pausePromise25 let pending = 026 async function createWorker () {27 // eslint-disable-next-line no-unmodified-loop-condition28 while (!stopped) {29 await new Promise((launchWorker) => unusedWorkers.push(launchWorker))30 let job31 while ((job = queue.shift())) {32 pending++33 if (pausePromise) await pausePromise34 if (stopped) return35 try {36 const res = processFn.call(context, job)37 if (res && res.then) await res38 } catch (err) {39 if (catchFn) await catchFn.call(context, err, job)40 else throw err41 }42 pending--43 if (drainLowWaterMark !== undefined && (queue.length + pending) <= drainLowWaterMark) {44 drainResolve()45 drainResolve = undefined46 drainLowWaterMark = undefined47 }48 }49 }50 }51 for (let i = 0; i < concurrency; i++) createWorker()52 return {53 get length () {54 return queue.length55 },56 pause () {57 let resolve58 const promise = new Promise((_resolve) => {59 resolve = _resolve60 })61 promise.resolve = resolve62 pausePromise = promise63 },64 resume () {65 if (!pausePromise) return66 pausePromise.resolve()67 pausePromise = undefined68 },69 stop () {70 stopped = true71 if (pausePromise) pausePromise.resolve()72 },73 push (data) {74 queue.push(data)75 if (unusedWorkers.length) unusedWorkers.shift()()76 },77 unshift (data) {78 queue.unshift(data)79 if (unusedWorkers.length) unusedWorkers.shift()()80 },81 clear () {82 queue.clear()83 return this84 },85 drain (lowWaterMark = 0) {86 if ((queue.length + pending) <= lowWaterMark) return87 return new Promise((resolve) => {88 drainResolve = resolve89 drainLowWaterMark = lowWaterMark90 })91 }92 }...

Full Screen

Full Screen

launchWorkerCommand.js

Source:launchWorkerCommand.js Github

copy

Full Screen

1/*2* Licensed under the Apache License, Version 2.0 (the "License");3* you may not use this file except in compliance with the License.4* You may obtain a copy of the License at5*6* http://www.apache.org/licenses/LICENSE-2.07*8* Unless required by applicable law or agreed to in writing, software9* distributed under the License is distributed on an "AS IS" BASIS,10* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11* See the License for the specific language governing permissions and12* limitations under the License.13*/14'use strict';15const LaunchWorker = require('./lib/launchWorker');16const { CaliperUtils } = require('@hyperledger/caliper-core');17// enforces singletons18const checkFn = (argv) => {19 const uniqueArgs = ['caliper-bind-sut', 'caliper-bind-args', 'caliper-bind-cwd', 'caliper-bind-file'];20 return CaliperUtils.checkSingleton(argv, uniqueArgs);21};22module.exports._checkFn = checkFn;23module.exports.command = 'worker [options]';24module.exports.describe = 'Launch a Caliper worker process to generate the benchmark workload';25module.exports.builder = yargs => {26 yargs.options({27 'caliper-bind-sut' : {describe: 'The name and version of the platform to bind to', type: 'string' },28 'caliper-bind-cwd' : {describe: 'The working directory for performing the SDK install', type: 'string' },29 'caliper-bind-args' : {describe: 'Additional arguments to pass to "npm install". Use the "=" notation when setting this parameter', type: 'string' },30 'caliper-bind-file' : {describe: 'Yaml file to override default (supported) package versions when binding an SDK', type: 'string' }31 });32 yargs.usage('Usage:\n caliper launch worker --caliper-bind-sut fabric:1.4 [other options]');33 // enforce singletons34 yargs.check(checkFn);35 return yargs;36};37module.exports.handler = (argv) => {38 return argv.thePromise = LaunchWorker.handler(argv);...

Full Screen

Full Screen

managed.js

Source:managed.js Github

copy

Full Screen

...7 do a graceful shutdown on Control-c including from8 Windows.9 */10let launchWorkerMain = () => {}; // defined later11function launchWorker(script, opts) {12 return launchWorkerMain(script, opts);13}14if (process.disconnect) {15 // running as a child16 const childMethods = runAsManagedChild(INTERRUPT_TYPE);17 launchWorker.onInterrupt = childMethods.onInterrupt;18 launchWorker.shutdown = childMethods.shutdown;19} else {20 // otherwise running as master21 const masterMethods = runAsMaster(INTERRUPT_TYPE);22 launchWorkerMain = masterMethods.launchChildWorker;23 launchWorker.onInterrupt = masterMethods.onInterrupt;24 launchWorker.shutdown = masterMethods.shutdown;25}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import ava from 'ava';2import {launchWorker} from 'ava/lib/worker/child';3import {resolve} from 'path';4import {fork} from 'child_process';5import {Observable} from 'rxjs/Observable';6import 'rxjs/add/observable/fromEvent';7import 'rxjs/add/operator/filter';8import 'rxjs/add/operator/map';9import 'rxjs/add/operator/take';10import 'rxjs/add/operator/timeout';11import 'rxjs/add/operator/timeoutWith';12import 'rxjs/add/operator/retryWhen';13import 'rxjs/add/operator/mergeMap';14import 'rxjs/add/operator/do';15import 'rxjs/add/operator/catch';16import 'rxjs/add/operator/delay';17const testFile = resolve(__dirname, 'test.js');18const testFile2 = resolve(__dirname, 'test2.js');19const testFile3 = resolve(__dirname, 'test3.js');20const forkOptions = {21 cwd: process.cwd(),22};23const forkTestFile = (file) => fork(file, forkOptions);24const forkTestFileAndLaunchWorker = (file) => {25 const childProcess = forkTestFile(file);26 return launchWorker(childProcess);27};28const forkTestFileAndLaunchWorkerWithRetry = (file) => {29 return forkTestFileAndLaunchWorker(file)30 .retryWhen(errors => errors31 .delay(1000)32 .take(2)33 );34};35ava('test', t => {36 return Observable.fromEvent(forkTestFileAndLaunchWorkerWithRetry(testFile), 'message')37 .filter(message => message.type === 'test')38 .timeout(5000)39 .map(message => message.test.title)40 .do(title => console.log(title))41 .toArray()42 .map(titles => titles.sort())43 .do(titles => console.log(titles))44 .map(titles => t.deepEqual(titles, ['test1', 'test2', 'test3']))45 .toPromise();46});47ava('test2', t => {48 return Observable.fromEvent(forkTestFileAndLaunchWorkerWithRetry(testFile2), 'message')49 .filter(message => message.type === 'test')50 .timeout(5000)51 .map(message => message.test.title)52 .do(title => console.log(title))53 .toArray()54 .map(titles => titles.sort())

Full Screen

Using AI Code Generation

copy

Full Screen

1const ava = require('ava')2const path = require('path')3const workerPath = path.join(__dirname, 'worker.js')4ava.launchWorker(workerPath, { test: 'test' })5const { parentPort } = require('worker_threads')6parentPort.on('message', (message) => {7 console.log(message)8})9{ test: 'test' }10const ava = require('ava')11const path = require('path')12const workerPath = path.join(__dirname, 'worker.js')13ava.launchWorker(workerPath, { test: 'test' }, { workerData: 'workerData' })14const { workerData } = require('worker_threads')15console.log(workerData)16const ava = require('ava')17const path = require('path')18const workerPath = path.join(__dirname, 'worker.js')19ava.launchWorker(workerPath, { test: 'test' }, { workerOptions: { eval: true } })20const { workerData } = require('worker_threads')21console.log(workerData)22MIT © [Arunoda Susiripala](

Full Screen

Using AI Code Generation

copy

Full Screen

1const { launchWorker } = require('workerpool');2const pool = launchWorker();3pool.exec('someMethod', [arg1, arg2])4 .then((result) => {5 })6 .catch((error) => {7 });8const { launchWorker } = require('workerpool');9const pool = launchWorker();10pool.exec('someMethod', [arg1, arg2])11 .then((result) => {12 })13 .catch((error) => {14 });15const { launchWorker } = require('workerpool');16const pool = launchWorker();17pool.exec('someMethod', [arg1, arg2])18 .then((result) => {19 })20 .catch((error) => {21 });22const { launchWorker } = require('workerpool');23const pool = launchWorker();24pool.exec('someMethod', [arg1, arg2])25 .then((result) => {26 })27 .catch((error) => {28 });

Full Screen

Using AI Code Generation

copy

Full Screen

1launchWorker({2 options: {3 }4});5launchWorker({6 options: {7 }8});9launchWorker({10 options: {11 }12});13launchWorker({14 options: {15 }16});17launchWorker({18 options: {19 }20});21launchWorker({22 options: {

Full Screen

Using AI Code Generation

copy

Full Screen

1var workerPath = "worker.js";2var worker = availableWorkers.launchWorker(workerPath);3worker.postMessage("hello");4var worker = availableWorkers.launchWorker(workerPath);5worker.postMessage("hello");6worker.postMessage("hello");7worker.postMessage("hello");8var worker = availableWorkers.launchWorker(workerPath);9worker.postMessage("hello");10worker.postMessage("hello");11worker.postMessage("hello");12worker.postMessage("hello");13var worker = availableWorkers.launchWorker(workerPath);

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ava automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful