Skip to content

Instantly share code, notes, and snippets.

View thakursaurabh1998's full-sized avatar
Getting Better

Saurabh Thakur thakursaurabh1998

Getting Better
View GitHub Profile

Keybase proof

I hereby claim:

  • I am thakursaurabh1998 on github.
  • I am thakursaurabh98 (https://keybase.io/thakursaurabh98) on keybase.
  • I have a public key whose fingerprint is F6E7 2387 24AB E8B3 58C4 706A 8C6F 585E 5FCB 70C3

To claim this, I am signing this object:

class Poll {
/**
* @typedef options
* @property {number} interval Interval between each poll in `seconds`
* @property {number} maxPollCount Max number of times to poll
*
* @param {options} options
* @param {(Object) => Promise<boolean>} pollingFunction
* @param {QueueClientInterface} queueClient
*/
class Poll {
/**
* @typedef options
* @property {number} interval Interval between each poll in `seconds`
* @property {number} maxPollCount Max number of times to poll
*
* @param {options} options
* @param {(Object) => Promise<boolean>} pollingFunction
* @param {QueueClientInterface} queueClient
*/
class Poll {
/**
* @typedef options
* @property {number} interval Interval between each poll in `seconds`
* @property {number} maxPollCount Max number of times to poll
*
* @param {options} options
* @param {(Object) => Promise<boolean>} pollingFunction
* @param {QueueClientInterface} queueClient
*/
class Poll {
constructor(...) {...}
/**
* Start polling
* @param {object} data dequeued data
* @param {boolean} prePoll poll before putting to queue
*/
async start(data) {
const pollCount = this.maxPollCount;
class Poll {
/**
* @typedef options
* @property {number} interval Interval between each poll in `seconds`
* @property {number} maxPollCount Max number of times to poll
*
* @param {options} options
* @param {(Object) => Boolean} pollingFunction
* @param {QueueClientInterface} queueClient
*/
const userPoll = new Poll(
{
interval: 2,
maxPollCount: 10,
},
pollingFunction,
queueClient,
logger
);
@thakursaurabh1998
thakursaurabh1998 / server.ts
Created March 16, 2022 20:21
Singleton Pattern in TS
import express, { Application } from "express";
export default class Server {
private app: Application
private static instance: Server;
private constructor() {
this.app = express();
this.app.listen(8000, () => {
console.log("Server started");
const async = require('async');
const { ConsumerGroup } = require('kafka-node');
const consumerConfig = {
kafkaHost: 'broker:9092',
groupId: 'order-service',
fetchMaxBytes: 100 * 1024, // 100 KB
autoCommit: false,
};
const async = require('async');
const { ConsumerGroup } = require('kafka-node');
const consumerConfig = {
kafkaHost: 'broker:9092',
groupId: 'order-service',
fetchMaxBytes: 100 * 1024, // 100 KB
autoCommit: false,
};