How to use concurrency method in stryker-parent

Best JavaScript code snippet using stryker-parent

ClientServerTest1.js

Source:ClientServerTest1.js Github

copy

Full Screen

1(function()2{3 "use strict";4 var Global,ClientServerTest1,WebSocketServer,S2CMessage,WebSocketClient,Website,Client,ClientServerTest1_Templates,ClientServerTest1_JsonEncoder,ClientServerTest1_JsonDecoder,WebSharper,UI,Var$1,Submitter,View,Remoting,AjaxRemotingProvider,Arrays,Concurrency,Doc,AspNetCore,WebSocket,Client$1,WithEncoding,JSON,Utils,IntelliFactory,Runtime,AttrProxy,Templating,Runtime$1,Server,ProviderBuilder,Handler,TemplateInstance,Client$2,Templates,ClientSideJson,Provider;5 Global=self;6 ClientServerTest1=Global.ClientServerTest1=Global.ClientServerTest1||{};7 WebSocketServer=ClientServerTest1.WebSocketServer=ClientServerTest1.WebSocketServer||{};8 S2CMessage=WebSocketServer.S2CMessage=WebSocketServer.S2CMessage||{};9 WebSocketClient=ClientServerTest1.WebSocketClient=ClientServerTest1.WebSocketClient||{};10 Website=ClientServerTest1.Website=ClientServerTest1.Website||{};11 Client=Website.Client=Website.Client||{};12 ClientServerTest1_Templates=Global.ClientServerTest1_Templates=Global.ClientServerTest1_Templates||{};13 ClientServerTest1_JsonEncoder=Global.ClientServerTest1_JsonEncoder=Global.ClientServerTest1_JsonEncoder||{};14 ClientServerTest1_JsonDecoder=Global.ClientServerTest1_JsonDecoder=Global.ClientServerTest1_JsonDecoder||{};15 WebSharper=Global.WebSharper;16 UI=WebSharper&&WebSharper.UI;17 Var$1=UI&&UI.Var$1;18 Submitter=UI&&UI.Submitter;19 View=UI&&UI.View;20 Remoting=WebSharper&&WebSharper.Remoting;21 AjaxRemotingProvider=Remoting&&Remoting.AjaxRemotingProvider;22 Arrays=WebSharper&&WebSharper.Arrays;23 Concurrency=WebSharper&&WebSharper.Concurrency;24 Doc=UI&&UI.Doc;25 AspNetCore=WebSharper&&WebSharper.AspNetCore;26 WebSocket=AspNetCore&&AspNetCore.WebSocket;27 Client$1=WebSocket&&WebSocket.Client;28 WithEncoding=Client$1&&Client$1.WithEncoding;29 JSON=Global.JSON;30 Utils=WebSharper&&WebSharper.Utils;31 IntelliFactory=Global.IntelliFactory;32 Runtime=IntelliFactory&&IntelliFactory.Runtime;33 AttrProxy=UI&&UI.AttrProxy;34 Templating=UI&&UI.Templating;35 Runtime$1=Templating&&Templating.Runtime;36 Server=Runtime$1&&Runtime$1.Server;37 ProviderBuilder=Server&&Server.ProviderBuilder;38 Handler=Server&&Server.Handler;39 TemplateInstance=Server&&Server.TemplateInstance;40 Client$2=UI&&UI.Client;41 Templates=Client$2&&Client$2.Templates;42 ClientSideJson=WebSharper&&WebSharper.ClientSideJson;43 Provider=ClientSideJson&&ClientSideJson.Provider;44 S2CMessage.LogInFailed={45 $:346 };47 WebSocketClient.WebSocketTest=function(endpoint)48 {49 var cmdInput,flag,arg1,arg2,user,vInput,submit,vTextView,container,b;50 function writen(fmt)51 {52 return fmt(function(s)53 {54 var x;55 x=self.document.createTextNode(s+"\n");56 container.elt.appendChild(x);57 });58 }59 cmdInput="";60 flag=0;61 arg1="";62 arg2="";63 user="";64 vInput=Var$1.Create$1("");65 submit=Submitter.CreateOption(vInput.get_View());66 vTextView=View.MapAsync(function(a)67 {68 var input,cmd,b$1,b$2,b$3,b$4,b$5,b$6,b$7,b$8,b$9;69 return a!=null&&a.$==1?(input=a.$0,(cmd=(new AjaxRemotingProvider.New()).Sync("ClientServerTest1:ClientServerTest1.WebSocketClient+ActorModule.SplitByComma:1982470384",[input]),Arrays.get(cmd,0)==="register"?Arrays.length(cmd)===3?(flag=1,cmdInput=Arrays.get(cmd,0),arg1=Arrays.get(cmd,1),arg2=Arrays.get(cmd,2),b$1=null,Concurrency.Delay(function()70 {71 return Concurrency.Return("");72 })):(flag=0,(new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketServer.ShowError:-1146015191",[input])):Arrays.get(cmd,0)==="login"?Arrays.length(cmd)===3?user===""?(flag=1,cmdInput=Arrays.get(cmd,0),user=Arrays.get(cmd,1),arg1=Arrays.get(cmd,1),arg2=Arrays.get(cmd,2),b$2=null,Concurrency.Delay(function()73 {74 return Concurrency.Return("");75 })):(flag=0,(new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketServer.DuplicateLogin:-1146015191",[input])):(flag=0,(new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketServer.ShowError:-1146015191",[input])):Arrays.get(cmd,0)==="logout"?Arrays.length(cmd)===1?(flag=1,cmdInput=Arrays.get(cmd,0),user!==""?(new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketServer.ShowLogOut:-1146015191",[user]):(flag=0,(new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketServer.ShowWrongOrder:-1146015191",[input]))):(flag=0,(new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketServer.ShowError:-1146015191",[input])):Arrays.get(cmd,0)==="subscribe"?Arrays.length(cmd)===2?(flag=1,cmdInput=Arrays.get(cmd,0),arg1=Arrays.get(cmd,1),user===""?(flag=0,(new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketServer.ShowWrongOrder:-1146015191",[input])):user===arg1?(flag=0,(new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketServer.SubYourself:-1146015191",[input])):(b$3=null,Concurrency.Delay(function()76 {77 return Concurrency.Return("");78 }))):(flag=0,(new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketServer.ShowError:-1146015191",[input])):Arrays.get(cmd,0)==="send"?Arrays.length(cmd)===2?(flag=1,cmdInput=Arrays.get(cmd,0),arg1=Arrays.get(cmd,1),user===""?(flag=0,(new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketServer.ShowWrongOrder:-1146015191",[input])):(b$4=null,Concurrency.Delay(function()79 {80 return Concurrency.Return("");81 }))):(flag=0,(new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketServer.ShowError:-1146015191",[input])):Arrays.get(cmd,0)==="retweet"?Arrays.length(cmd)===2?(flag=1,cmdInput=Arrays.get(cmd,0),arg1=Arrays.get(cmd,1),user===""?(flag=0,(new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketServer.ShowWrongOrder:-1146015191",[input])):(b$5=null,Concurrency.Delay(function()82 {83 return Concurrency.Return("");84 }))):(flag=0,(new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketServer.ShowError:-1146015191",[input])):Arrays.get(cmd,0)==="query"?Arrays.length(cmd)===3?Arrays.get(cmd,1)==="tag"?(flag=1,cmdInput=Arrays.get(cmd,0),arg1=Arrays.get(cmd,1),arg2=Arrays.get(cmd,2),user===""?(flag=0,(new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketServer.ShowWrongOrder:-1146015191",[input])):(b$6=null,Concurrency.Delay(function()85 {86 return Concurrency.Return("");87 }))):Arrays.get(cmd,1)==="mentioned"?(flag=1,cmdInput=Arrays.get(cmd,0),arg1=Arrays.get(cmd,1),arg2=Arrays.get(cmd,2),user===""?(flag=0,(new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketServer.ShowWrongOrder:-1146015191",[input])):(b$7=null,Concurrency.Delay(function()88 {89 return Concurrency.Return("");90 }))):Arrays.get(cmd,1)==="username"?(flag=1,cmdInput=Arrays.get(cmd,0),arg1=Arrays.get(cmd,1),arg2=Arrays.get(cmd,2),user===""?(flag=0,(new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketServer.ShowWrongOrder:-1146015191",[input])):(b$8=null,Concurrency.Delay(function()91 {92 return Concurrency.Return("");93 }))):(flag=0,(new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketServer.ShowError:-1146015191",[input])):(flag=0,(new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketServer.ShowError:-1146015191",[input])):(flag=0,(new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketServer.ShowError:-1146015191",[input])))):(flag=0,b$9=null,Concurrency.Delay(function()94 {95 return Concurrency.Return("");96 }));97 },submit.view);98 container=Doc.Element("pre",[],[]);99 Concurrency.Start((b=null,Concurrency.Delay(function()100 {101 return Concurrency.Bind(WithEncoding.ConnectStateful(function(a)102 {103 return JSON.stringify((ClientServerTest1_JsonEncoder.j())(a));104 },function(a)105 {106 return(ClientServerTest1_JsonDecoder.j())(JSON.parse(a));107 },endpoint,function()108 {109 var b$1;110 b$1=null;111 return Concurrency.Delay(function()112 {113 return Concurrency.Return([0,function(state)114 {115 return function(msg)116 {117 var b$2;118 b$2=null;119 return Concurrency.Delay(function()120 {121 var data,username,username$1,username$2,subscribeto,subscribeto$1,username$3,tweetcontent,username$4,username$5;122 return msg.$==3?(writen(function($1)123 {124 return $1("WebSocket connection closed.");125 }),Concurrency.Return(state)):msg.$==2?(writen(function($1)126 {127 return $1("WebSocket connection open.");128 }),Concurrency.Return(state)):msg.$==1?(writen(function($1)129 {130 return $1("WebSocket connection error!");131 }),Concurrency.Return(state)):(data=msg.$0,Concurrency.Combine(data.$==1?((writen(function($1)132 {133 return function($2)134 {135 return $1("Registed failed, "+Utils.toSafe($2)+" has already been registed!");136 };137 }))(data.$0),Concurrency.Zero()):data.$==2?(username=data.$0,((writen(function($1)138 {139 return function($2)140 {141 return $1(Utils.toSafe($2)+" logged in.");142 };143 }))(username),(writen(function($1)144 {145 return function($2)146 {147 return $1("Welcome, "+Utils.toSafe($2)+"!");148 };149 }))(username),(writen(function($1)150 {151 return function($2)152 {153 return $1("----Current User: "+Utils.toSafe($2)+"----");154 };155 }))(username),Concurrency.Bind((new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketClient+ActorModule.LogInSuccess:1131399653",[username]),function()156 {157 return Concurrency.Return(null);158 }))):data.$==3?(user="",writen(function($1)159 {160 return $1("Invalid username or password!");161 }),Concurrency.Zero()):data.$==4?(username$1=data.$0,((writen(function($1)162 {163 return function($2)164 {165 return $1(Utils.toSafe($2)+" logged out.");166 };167 }))(username$1),Concurrency.Bind((new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketClient+ActorModule.LogOutSuccess:1131399653",[username$1]),function()168 {169 return Concurrency.Return(null);170 }))):data.$==5?(username$2=data.$0,(subscribeto=data.$1,(((writen(Runtime.Curried3(function($1,$2,$3)171 {172 return $1(Utils.toSafe($2)+" subscribes "+Utils.toSafe($3)+" successfully.");173 })))(username$2))(subscribeto),Concurrency.Bind((new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketClient+ActorModule.Subscribing:-685279371",[username$2,subscribeto]),function()174 {175 return Concurrency.Return(null);176 })))):data.$==6?(subscribeto$1=data.$1,((((writen(Runtime.Curried(function($1,$2,$3,$4)177 {178 return $1(Utils.toSafe($2)+" does not exist or "+Utils.toSafe($3)+" has already subscribed to "+Utils.toSafe($4)+".");179 },4)))(subscribeto$1))(data.$0))(subscribeto$1),Concurrency.Zero())):data.$==7?Concurrency.Bind((new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketClient+ActorModule.BeSubscribed:-685279371",[data.$0,data.$1]),function()180 {181 return Concurrency.Return(null);182 }):data.$==8?(username$3=data.$0,(tweetcontent=data.$1,Concurrency.Bind((new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketClient+ActorModule.ResponseSendTweet:-47597098",[username$3,tweetcontent,data.$2]),function()183 {184 ((writen(Runtime.Curried3(function($1,$2,$3)185 {186 return $1(Utils.toSafe($2)+" sends a tweet: "+Utils.toSafe($3));187 })))(username$3))(tweetcontent);188 return Concurrency.Zero();189 }))):data.$==9?(username$4=data.$0,Concurrency.Bind((new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketClient+ActorModule.ResponseReTweet:-685279371",[username$4,data.$1]),function()190 {191 (writen(function($1)192 {193 return function($2)194 {195 return $1(Utils.toSafe($2)+" retweets successfully.");196 };197 }))(username$4);198 return Concurrency.Zero();199 })):data.$==10?Concurrency.Bind((new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketClient+ActorModule.QueryByTag:-685279371",[data.$0,data.$1]),function()200 {201 writen(function($1)202 {203 return $1("Query By Tag, please check console for details.");204 });205 return Concurrency.Zero();206 }):data.$==11?Concurrency.Bind((new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketClient+ActorModule.QueryByMentioned:-685279371",[data.$0,data.$1]),function()207 {208 writen(function($1)209 {210 return $1("Query By Mentioned, please check console for details.");211 });212 return Concurrency.Zero();213 }):data.$==12?Concurrency.Bind((new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketClient+ActorModule.QueryByUsername:-685279371",[data.$0,data.$1]),function()214 {215 writen(function($1)216 {217 return $1("Query By Username, please check console for details.");218 });219 return Concurrency.Zero();220 }):(username$5=data.$0,((writen(function($1)221 {222 return function($2)223 {224 return $1(Utils.toSafe($2)+" registed successfully, password: *** ");225 };226 }))(username$5),Concurrency.Bind((new AjaxRemotingProvider.New()).Async("ClientServerTest1:ClientServerTest1.WebSocketClient+ActorModule.RegisterSuccess:-685279371",[username$5,data.$1]),function()227 {228 return Concurrency.Return(null);229 }))),Concurrency.Delay(function()230 {231 return Concurrency.Return(state+1);232 })));233 });234 };235 }]);236 });237 }),function(a)238 {239 return Concurrency.While(function()240 {241 return true;242 },Concurrency.Delay(function()243 {244 return flag===1?(flag=0,cmdInput==="register"?Concurrency.Bind(Concurrency.Sleep(500),function()245 {246 a.Post({247 $:0,248 $0:arg1,249 $1:arg2250 });251 return Concurrency.Zero();252 }):cmdInput==="login"?Concurrency.Bind(Concurrency.Sleep(500),function()253 {254 a.Post({255 $:1,256 $0:arg1,257 $1:arg2258 });259 return Concurrency.Zero();260 }):cmdInput==="logout"?Concurrency.Bind(Concurrency.Sleep(500),function()261 {262 a.Post({263 $:2,264 $0:user265 });266 user="";267 return Concurrency.Zero();268 }):cmdInput==="subscribe"?Concurrency.Bind(Concurrency.Sleep(500),function()269 {270 a.Post({271 $:3,272 $0:user,273 $1:arg1274 });275 return Concurrency.Zero();276 }):cmdInput==="send"?Concurrency.Bind(Concurrency.Sleep(500),function()277 {278 a.Post({279 $:4,280 $0:user,281 $1:arg1282 });283 return Concurrency.Zero();284 }):cmdInput==="retweet"?Concurrency.Bind(Concurrency.Sleep(500),function()285 {286 a.Post({287 $:5,288 $0:user,289 $1:arg1290 });291 return Concurrency.Zero();292 }):cmdInput==="query"?arg1==="tag"?Concurrency.Bind(Concurrency.Sleep(500),function()293 {294 a.Post({295 $:6,296 $0:user,297 $1:arg2298 });299 return Concurrency.Zero();300 }):arg1==="mentioned"?Concurrency.Bind(Concurrency.Sleep(500),function()301 {302 a.Post({303 $:7,304 $0:user,305 $1:arg2306 });307 return Concurrency.Zero();308 }):arg1==="username"?Concurrency.Bind(Concurrency.Sleep(500),function()309 {310 a.Post({311 $:8,312 $0:user,313 $1:arg2314 });315 return Concurrency.Zero();316 }):Concurrency.Zero():Concurrency.Zero()):flag===0?Concurrency.Bind(Concurrency.Sleep(500),function()317 {318 return Concurrency.Return(null);319 }):Concurrency.Zero();320 }));321 });322 })),null);323 return Doc.Element("div",[],[Doc.Input([],vInput),Doc.Button("Send",[],function()324 {325 submit.Trigger();326 }),Doc.Element("hr",[],[]),Doc.Element("h4",[AttrProxy.Create("class","text-muted")],[Doc.TextNode("The server responded:")]),Doc.Element("div",[AttrProxy.Create("class","jumbotron")],[Doc.Element("h4",[],[Doc.TextView(vTextView)])]),container]);327 };328 Client.Main=function(aboutPageLink,wsep)329 {330 var b,W,_this,p,i;331 return(b=(W=WebSocketClient.WebSocketTest(wsep),(_this=new ProviderBuilder.New$1(),(_this.h.push({332 $:0,333 $0:"websockettest",334 $1:W335 }),_this))),(p=Handler.CompleteHoles(b.k,b.h,[]),(i=new TemplateInstance.New(p[1],ClientServerTest1_Templates.body(p[0])),b.i=i,i))).get_Doc();336 };337 ClientServerTest1_Templates.body=function(h)338 {339 Templates.LoadLocalTemplates("main");340 return h?Templates.NamedTemplate("main",{341 $:1,342 $0:"body"343 },h):void 0;344 };345 ClientServerTest1_JsonEncoder.j=function()346 {347 return ClientServerTest1_JsonEncoder._v?ClientServerTest1_JsonEncoder._v:ClientServerTest1_JsonEncoder._v=(Provider.EncodeUnion(void 0,{348 queriedusername:8,349 mentioned:7,350 tag:6,351 tweetcontent5:5,352 tweetcontent4:4,353 subscribeto3:3,354 username2:2,355 psw1:1,356 psw0:0357 },[["RequestRegister",[["$0","username0",Provider.Id(),0],["$1","psw0",Provider.Id(),0]]],["RequestLogIn",[["$0","username1",Provider.Id(),0],["$1","psw1",Provider.Id(),0]]],["RequestLogOut",[["$0","username2",Provider.Id(),0]]],["WantSubscribe",[["$0","username3",Provider.Id(),0],["$1","subscribeto3",Provider.Id(),0]]],["WantSendTweet",[["$0","username4",Provider.Id(),0],["$1","tweetcontent4",Provider.Id(),0]]],["WantReTweet",[["$0","username5",Provider.Id(),0],["$1","tweetcontent5",Provider.Id(),0]]],["WantQueryByTag",[["$0","username6",Provider.Id(),0],["$1","tag",Provider.Id(),0]]],["WantQueryByMentioned",[["$0","username7",Provider.Id(),0],["$1","mentioned",Provider.Id(),0]]],["WantQueryByUsername",[["$0","username8",Provider.Id(),0],["$1","queriedusername",Provider.Id(),0]]]]))();358 };359 ClientServerTest1_JsonDecoder.j=function()360 {361 return ClientServerTest1_JsonDecoder._v?ClientServerTest1_JsonDecoder._v:ClientServerTest1_JsonDecoder._v=(Provider.DecodeUnion(void 0,"type",[["RegisterSuccess",[["$0","username9",Provider.Id(),0],["$1","psw9",Provider.Id(),0]]],["RegisterFailed",[["$0","username19",Provider.Id(),0]]],["LogInSuccess",[["$0","username10",Provider.Id(),0],["$1","psw10",Provider.Id(),0]]],["LogInFailed",[]],["LogOutSuccess",[["$0","username11",Provider.Id(),0]]],["Subscribing",[["$0","username12",Provider.Id(),0],["$1","subscribeto12",Provider.Id(),0]]],["SubscribeFailed",[["$0","username20",Provider.Id(),0],["$1","subscribeto20",Provider.Id(),0]]],["BeSubscribed",[["$0","subscribeto13",Provider.Id(),0],["$1","username13",Provider.Id(),0]]],["ResponseSendTweet",[["$0","username14",Provider.Id(),0],["$1","tweetcontent14",Provider.Id(),0],["$2","followers14",Provider.DecodeList(Provider.Id()),0]]],["ResponseReTweet",[["$0","username15",Provider.Id(),0],["$1","tweetcontent15",Provider.Id(),0]]],["QueryByTag",[["$0","username16",Provider.Id(),0],["$1","tag16",Provider.Id(),0]]],["QueryByMentioned",[["$0","username17",Provider.Id(),0],["$1","mentioned17",Provider.Id(),0]]],["QueryByUsername",[["$0","username18",Provider.Id(),0],["$1","queriedusername18",Provider.Id(),0]]]]))();362 };...

Full Screen

Full Screen

concurrent-mapper.js

Source:concurrent-mapper.js Github

copy

Full Screen

1/**2 * @license Copyright 2019 The Lighthouse Authors. All Rights Reserved.3 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.04 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.5 */6'use strict';7/**8 * A class that maintains a concurrency pool to coordinate many jobs that should9 * only be run `concurrencyLimit` at a time.10 * API inspired by http://bluebirdjs.com/docs/api/promise.map.html, but11 * independent callers of `concurrentMap()` share the same concurrency limit.12 */13class ConcurrentMapper {14 constructor() {15 /** @type {Set<Promise<unknown>>} */16 this._promisePool = new Set();17 /**18 * The limits of all currently running jobs. There will be duplicates.19 * @type {Array<number>}20 */21 this._allConcurrencyLimits = [];22 }23 /**24 * Runs callbackfn on `values` in parallel, at a max of `concurrency` at a25 * time. Resolves to an array of the results or rejects with the first26 * rejected result. Default `concurrency` limit is `Infinity`.27 * @template T, U28 * @param {Array<T>} values29 * @param {(value: T, index: number, array: Array<T>) => Promise<U>} callbackfn30 * @param {{concurrency: number}} [options]31 * @return {Promise<Array<U>>}32 */33 static async map(values, callbackfn, options) {34 const cm = new ConcurrentMapper();35 return cm.pooledMap(values, callbackfn, options);36 }37 /**38 * Returns whether there are fewer running jobs than the minimum current39 * concurrency limit and the proposed new `concurrencyLimit`.40 * @param {number} concurrencyLimit41 */42 _canRunMoreAtLimit(concurrencyLimit) {43 return this._promisePool.size < concurrencyLimit &&44 this._promisePool.size < Math.min(...this._allConcurrencyLimits);45 }46 /**47 * Add a job to pool.48 * @param {Promise<unknown>} job49 * @param {number} concurrencyLimit50 */51 _addJob(job, concurrencyLimit) {52 this._promisePool.add(job);53 this._allConcurrencyLimits.push(concurrencyLimit);54 }55 /**56 * Remove a job from pool.57 * @param {Promise<unknown>} job58 * @param {number} concurrencyLimit59 */60 _removeJob(job, concurrencyLimit) {61 this._promisePool.delete(job);62 const limitIndex = this._allConcurrencyLimits.indexOf(concurrencyLimit);63 if (limitIndex === -1) {64 throw new Error('No current limit found for finishing job');65 }66 this._allConcurrencyLimits.splice(limitIndex, 1);67 }68 /**69 * Runs callbackfn on `values` in parallel, at a max of `concurrency` at70 * a time across all callers on this instance. Resolves to an array of the71 * results (for each caller separately) or rejects with the first rejected72 * result. Default `concurrency` limit is `Infinity`.73 * @template T, U74 * @param {Array<T>} values75 * @param {(value: T, index: number, array: Array<T>) => Promise<U>} callbackfn76 * @param {{concurrency: number}} [options]77 * @return {Promise<Array<U>>}78 */79 async pooledMap(values, callbackfn, options = {concurrency: Infinity}) {80 const {concurrency} = options;81 const result = [];82 for (let i = 0; i < values.length; i++) {83 // Wait until concurrency allows another run.84 while (!this._canRunMoreAtLimit(concurrency)) {85 // Unconditionally catch since we only care about our own failures86 // (caught in the Promise.all below), not other callers.87 await Promise.race(this._promisePool).catch(() => {});88 }89 // innerPromise removes itself from the pool and resolves on return from callback.90 const innerPromise = callbackfn(values[i], i, values)91 .finally(() => this._removeJob(innerPromise, concurrency));92 this._addJob(innerPromise, concurrency);93 result.push(innerPromise);94 }95 return Promise.all(result);96 }97}...

Full Screen

Full Screen

concurrency.ts

Source:concurrency.ts Github

copy

Full Screen

1import Callable from '@alirya/function/callable';2import Argument from '@alirya/function/argument/argument';3export async function ConcurrencyParameters<4 Callback extends Callable,5>(6 event : Iterable<Callback>,7 concurrency : number,8 argument : Parameters<Callback>9) : Promise<ReturnType<Callback>[]>;10export async function ConcurrencyParameters<11 Callback extends Callable,12>(13 event : Iterable<Callback>,14 concurrency : number,15) : Promise<ReturnType<Callback>[]>;16export async function ConcurrencyParameters<17 Callback extends Callable,18>(19 event : Iterable<Callback>,20 concurrency : number,21 argument : Parameters<Callback>|[] = []22) : Promise<ReturnType<Callback>[]> {23 const returns : ReturnType<Callback>[] = [];24 const buffers : ReturnType<Callback>[] = [];25 for (const callback of event) {26 buffers.push(27 callback(...argument) as ReturnType<Callback>28 );29 if(buffers.length === concurrency) {30 returns.push(...await Promise.all(buffers));31 buffers.length = 0;32 }33 }34 // last and less than concurrency35 if(buffers.length) {36 returns.push(...await Promise.all(buffers));37 }38 return returns;39}40export type ConcurrencyArgument<Callback extends Callable> = Argument<Parameters<Callback>> & {41 event : Iterable<Callback>42};43export async function ConcurrencyParameter<44 Callback extends Callable,45>( {46 event,47 concurrency,48 argument49 } : ConcurrencyArgument<Callback> & {concurrency:number}50) : Promise<ReturnType<Callback>[]> {51 return ConcurrencyParameters(event, concurrency, argument);52}53namespace Concurrency {54 export const Parameters = ConcurrencyParameters;55 export const Parameter = ConcurrencyParameter;56 export type Argument<Callback extends Callable> = ConcurrencyArgument<Callback>;57}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Stryker } = require('stryker-parent');2const { ConfigReader } = require('stryker-parent/src/core/config/ConfigReader');3const configReader = new ConfigReader();4const config = configReader.readConfig();5const stryker = new Stryker(config);6stryker.runMutationTest()7 .then(() => {8 console.log('done');9 })10 .catch((error) => {11 console.error(error);12 process.exit(1);13 });14const { ConfigReader } = require('stryker-parent/src/core/config/ConfigReader');15const { ConfigReader } = require('stryker-parent/src/core/config/ConfigReader');16const { ConfigReader } = require('stryker-parent/src/core/config/ConfigReader');17const { ConfigReader } = require('stryker-parent/src/core/config/ConfigReader');18const { ConfigReader } = require('stryker-parent/src/core/config/ConfigReader');19const { ConfigReader } = require('stryker-parent/src/core/config/ConfigReader');20const { ConfigReader } = require('stryker-parent/src/core/config/ConfigReader');21const { ConfigReader } = require('stryker-parent/src/core/config/ConfigReader');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Stryker } = require('stryker-parent');2const { StrykerJestRunner } = require('stryker-jest-runner');3const stryker = new Stryker({4 jest: {5 config: require('./jest.config.js'),6 },7});8stryker.runMutationTest();9module.exports = {10};11function add(a, b) {12 return a + b;13}14function subtract(a, b) {15 return a - b;16}17function multiply(a, b) {18 return a * b;19}20function divide(a, b) {21 return a / b;22}23module.exports = {24};25const { add } = require('../app');26test('add', () => {27 expect(add(2, 2)).toBe(4);28});29const { subtract } = require('../app');30test('subtract', () => {31 expect(subtract(2, 2)).toBe(0);32});33const { multiply } = require('../app');34test('multiply', () => {35 expect(multiply(2, 2)).toBe(4);36});37const { divide } = require('../app');38test('divide', () => {39 expect(divide(2, 2)).toBe(1);40});

Full Screen

Using AI Code Generation

copy

Full Screen

1const concurrency = require('stryker').concurrency;2module.exports = function(config) {3 concurrency(config, function() {4 config.set({5 mochaOptions: {6 }7 });8 });9};

Full Screen

Using AI Code Generation

copy

Full Screen

1const Stryker = require('stryker-parent').Stryker;2const stryker = new Stryker();3stryker.runMutationTest({4}).then(() => {5 console.log('Done!');6});7const Stryker = require('stryker-parent').Stryker;8const stryker = new Stryker();9stryker.runMutationTest({10}).then(() => {11 console.log('Done!');12});13const Stryker = require('stryker-parent').Stryker;14const stryker = new Stryker();15stryker.runMutationTest({16}).then(() => {17 console.log('Done!');18});19const Stryker = require('stryker-parent').Stryker;20const stryker = new Stryker();21stryker.runMutationTest({22}).then(() => {23 console.log('Done!');24});25const Stryker = require('stryker-parent').Stryker;26const stryker = new Stryker();27stryker.runMutationTest({28}).then(() => {29 console.log('Done!');30});31const Stryker = require('stryker-parent').Stryker;32const stryker = new Stryker();33stryker.runMutationTest({34}).then(() => {

Full Screen

Using AI Code Generation

copy

Full Screen

1var strykerParent = require('stryker-parent');2strykerParent.runInChildProcess();3var stryker = require('stryker');4var Stryker = stryker.Stryker;5var StrykerConfigReader = stryker.config.StrykerConfigReader;6var StrykerConfigWriter = stryker.config.StrykerConfigWriter;7var log4js = require('log4js');8var log = log4js.getLogger('Stryker');9var Promise = require('es6-promise').Promise;10var path = require('path');11var configReader = new StrykerConfigReader();12var configWriter = new StrykerConfigWriter();13var strykerOptions = configReader.readConfig();14var stryker = new Stryker(strykerOptions);15configWriter.writeConfig(strykerOptions);16log.info('Starting stryker with options: ', strykerOptions);17stryker.runMutationTest()18 .then(function (result) {19 log.info('Done running mutation test!');20 process.exit(result);21 })22 .catch(function (error) {23 log.error('An error occurred', error);24 process.exit(1);25 });26module.exports = function (config) {27 config.set({28 karma: {29 config: {30 preprocessors: {31 },32 coverageReporter: {33 },34 }35 },36 htmlReporter: {37 },38 clearTextReporter: {39 },40 });41};42module.exports = function (config) {43 config.set({

Full Screen

Using AI Code Generation

copy

Full Screen

1var concurrency = require('stryker-parent').concurrency;2concurrency(2, function (done) {3 done();4});5module.exports = function(config) {6 config.set({7 concurrency: {8 }9 });10};

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Stryker } = require('stryker-parent');2const strykerConfig = {3};4Stryker.run(strykerConfig).then(() => {5 console.log('Done!');6});7{8 "scripts": {9 }10}11const { Stryker } = require('stryker');12const strykerConfig = {13};14Stryker.run(strykerConfig).then(() => {15 console.log('Done!');16});17{18 "scripts": {19 }20}21const { Stryker } = require('stryker');

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 stryker-parent 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