Skip to content

Latest commit

 

History

History
64 lines (42 loc) · 1.29 KB

Dispatcher.md

File metadata and controls

64 lines (42 loc) · 1.29 KB

Dispatcher

class Dispatcher

import Dispatcher from 'ex-stream/Dispatcher';

Call executor with matched inputData

import { createServer } from 'http';
import { dispatch } from 'ex-stream/Dispatcher';

const matcher = req => requestParser(req);
const executor = params => JSON.stringify(params);

createServer((req, res) => {
   dispatch(matcher, executor)
     .on(res)
}).listen(3000, 'localhost');

Constructor

Parameters:

  • matcher: function (inputData: *) - function matches inputData and returns matchedData
  • executor: function (matched: *) - function executed with matchedData and returns value or Promise that passed to stream

Creates Dispatcher stream instance

function matcher(inputData) {
   // ...
 }
 function executor(matchedData) {
   // ...
 }

 new Dispatcher(matcher, executor);

function dispatch

import { dispatch } from 'ex-stream/Dispatcher';
function dispatch(matcher, executor)