This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calculateSomeFormula(param1, param2) { | |
validateParams(param1, param2); | |
return (param1 * 2) * (param2 * 3); | |
} | |
// although return value is not used in our example but this method can also return value which can be used by the caller | |
function validateParams(param1, param2) { | |
if (!param1) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calculateSomeFormula(param1, param2) { | |
if (!param1) { | |
throw new Error('Param1 is not defined'); | |
} | |
if (isNaN(param1)) { | |
throw new Error('Param1 is not a number'); | |
} | |
if (!param2) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calculateSomeFormula(param1, param2) { | |
if (param1) { | |
if (!isNaN(param1)) { | |
if (param2) { | |
if (!isNaN(param2)) { | |
return (param1 * 2) * (param2 * 3); | |
} else { | |
throw new Error('Param2 is not a number'); | |
} | |
} else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"studentId": "5e727fa7b9f23a1c643e671f", | |
"firstName": "Danish", | |
"lastName": "Siddiq", | |
"registrationNumber": 543678, | |
"email": "[email protected]" | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
query getStudent($studentId: String, $firstName: String) { | |
byId: findOne(input: {_id: $studentId}) { | |
...studentFields | |
} | |
byName: findOne(input: {firstName: $firstName}) { | |
...studentFields | |
} | |
} | |
mutation createStudent($firstName: String!, $lastName: String!, $registrationNumber: Int!, $email: String!) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Router } = require('express'); | |
const express_graphql = require('express-graphql'); | |
const { buildSchema } = require('graphql'); | |
const studentController = require('./student.ctrl'); | |
// GraphQL schema | |
const schema = buildSchema(` | |
scalar Date | |
, input SearchInput { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
apps : [ | |
{ | |
name : 'Custering', | |
script : 'Clustering/src/app.babel-register.js', | |
exec_mode : 'cluster_mode', | |
instances : 'max' | |
}, | |
{ | |
name : 'Clustering_Replcia', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// parentPort for registering to events from main thread | |
// workerData for receiving data clone | |
const { parentPort, workerData } = require('worker_threads'); | |
let interval; | |
let index = -1; | |
registerForEventListening(); | |
function registerForEventListening () { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// module included to create worker threads | |
const { Worker } = require('worker_threads'); | |
// main attributes | |
let lst; // list will be populated from 0 to n | |
let index = -1; // index will be used to traverse list | |
let myWorker; // worker reference | |
let interval; | |
mainBody(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class AsyncListController { | |
createList = async(req, res) => { | |
await this.populateHugeList(); | |
res.json({ ProcessId: 'Worker Process Id' + process.pid }); | |
}; | |
/* populate list with million elements | |
*/ | |
populateHugeList = async() => { |
NewerOlder