Create a stream listener

@return callable Returns a callback
198276
private function createStreamListener()
    {
        $callback = function ($event, $status, $events, $stream) {
            if (!isset($this->streamEvents[(int) $stream])) {
                return;
            }

            if (($events | 4) === 4) {
                // Disconnected
                return;
            }

            if (isset($this->readStreams[(int) $stream]) && ($events & \UV::READABLE)) {
                \call_user_func($this->readStreams[(int) $stream], $stream);
            }

            if (isset($this->writeStreams[(int) $stream]) && ($events & \UV::WRITABLE)) {
                \call_user_func($this->writeStreams[(int) $stream], $stream);
            }
        };

        return $callback;
    }
768797
public function notifyListeners() {

        foreach ($this->listeners as $listener) {

            $listenerClass = $listener['listener'];
            $handler = array($listenerClass, 'on_' . $this->state);
            if(!class_exists($listenerClass)) {
                throw new \Exception($listenerClass . ' does not exist');
            }

            if ($this->state == $listener['event'] && is_callable($handler)) {
                unset($listener['listener']);     
                
                $eventListener = new $listenerClass($this->logger, $this->request, $this->response);
                $eventListener->setDatasources($this->datasourceFactory, $this->datasources);
                $eventListener->setDatasourceKey($this->datasourceKey);
                $eventListener->setEventDispatcher($this->eventDispatcher);
                $eventListener->setConfig($listener);
                $eventListener->setCacheManager($this->cacheManager);
                $eventListener->setContainer($this->container);

                $eventListener->execute($this->state, $this->event);

            }
        }
      
     
    }
772246
function Listener() {
		// setup abstract layer
		core.ListenerAbstract.apply(this, arguments);

		var self = this;

		// in case the process die, the connection will be severed
		this.object.on('exit', function () {
			if (self.online === true) {
				this.emit('close');
			}
		});

		process.nextTick(function () {
			// setup a new connection with the object
			self.emit('listening');

			// setup a new connection with the object
			self.emit('connection', self.object);
		});
	}
1010745
public function createClassListener($listener)
    {
        $container = $this->container;

        return function () use ($listener, $container)
        {
            return call_user_func_array(
                $this->createClassCallable($listener, $container),
                func_get_args()
            );
        };
    }
868937
public function listenersAction()
    {
        $dispatcher = $this->get('event_dispatcher');

        $listenerNames = array_keys($dispatcher->getListeners());
        sort($listenerNames);

        $output = '<pre>';
        $output .= str_repeat('=', 3).str_pad(' Events / Listeners ', 80, '=').PHP_EOL.PHP_EOL;

        foreach ($listenerNames as $listenerName) {
            $listeners = $dispatcher->getListeners($listenerName);

            $output .= $listenerName.' (<a href="#'.$listenerName.'">'.count($listeners).' listeners</a>)'.PHP_EOL;
        }

        foreach ($listenerNames as $listenerName) {
            $listeners = $dispatcher->getListeners($listenerName);

            if (!$listenerName) {
                $listenerName = '(global)';
            }

            $output .= PHP_EOL.PHP_EOL.str_repeat('-', 3).'<a name="'.$listenerName.'"></a>'.str_pad(' '.$listenerName.' ', 80, '-').PHP_EOL.PHP_EOL;

            foreach ($listeners as $listener) {
                if (is_array($listener)) {
                    if (is_object($listener[0])) {
                        $listener = get_class($listener[0]).'->'.$listener[1].'()';
                    } else {
                        $listener = implode('::', $listener).'()';
                    }
                }
                $output .= '* '.$listener.PHP_EOL;
            }
        }

        return new Response($output);
    }
113724
public function withLocalScope()
    {
        if ($this->isClosed()) {
            throw new \RuntimeException("The stream is closed");
        }
        
        if (!$this->isGlobal()) {
            return $this;
        }
        
        $stream = clone $this;
        
        fwrite($stream->handle, (string)$this);
        
        return $stream;
    }
1150227
function Listener() {
		// setup abstract layer
		core.ListenerAbstract.apply(this, arguments);

		// parse the argument
		if (!(this.object instanceof net.Server)) {

			// create a new TCP server
			if (typeof this.object === 'number' || typeof this.object === 'string') {
				this.object = net.createServer().listen(this.object);
			} else {
				this.object = net.createServer().listen(this.object.port, this.object.host);
			}

			this.object.on('listening', this.emit.bind(this, 'listening'));
		} else {
			this.emit('listening');
		}

		// relay errors
		this.object.on('error', this.emit.bind(this, 'error'));

		// relay the close event
		this.object.on('close', this.emit.bind(this, 'close'));

		var self = this;
		// when a remote has connected to this server, this TCP event will emit
		this.object.on('connection', function (socket) {

			// we will emit the connection event to create a new communication object
			// the socket argument set here will be this.object in the new communication object
			self.emit('connection', socket);
		});
	}
1083242
public function getStream()
    {
        if ($this->stream === null) {
            return $this->streamFactory->newMessagePartStream($this);
        }
        $this->stream->rewind();
        return $this->stream;
    }
799190
private function createStreamCallback()
    {
        $read =& $this->readListeners;
        $write =& $this->writeListeners;
        $this->streamCallback = function ($stream, $flags) use (&$read, &$write) {
            $key = (int) $stream;

            if (Event::READ === (Event::READ & $flags) && isset($read[$key])) {
                \call_user_func($read[$key], $stream);
            }

            if (Event::WRITE === (Event::WRITE & $flags) && isset($write[$key])) {
                \call_user_func($write[$key], $stream);
            }
        };
    }
161857
protected function getStreamingWrapperCreator()
    {
        return function ($connection, $callback) {
            return function ($state, $response) use ($connection, $callback) {
                \call_user_func($callback, $response, $connection, null);
            };
        };
    }
1333418
function addToStream(stream) {
  // Don't add more than once
  if (stream.listeners('addListener').includes(addListener)) {
    return stream;
  }

  stream.on('newListener', addListener);

  return stream;
}
1360723
@Override
  public StreamImpl stream()
    throws IOException
  {
    if (_streamImpl == null) {
      _streamImpl = new SocketStream();
    }

    _streamImpl.init(_s);

    return _streamImpl;
  }
779871
public function getStream()
    {
        if (!$this->_stream instanceof StreamInterface) {
            if ($this->_stream === null) {
                if ($this->getError() !== UPLOAD_ERR_OK) {
                    throw new \RuntimeException('Unable to create file stream due to upload error: ' . $this->getError());
                }
                $stream = [
                    '__class' => FileStream::class,
                    'filename' => $this->tempFilename,
                    'mode' => 'r',
                ];
            } elseif ($this->_stream instanceof \Closure) {
                $stream = \call_user_func($this->_stream, $this);
            } else {
                $stream = $this->_stream;
            }

            $this->_stream = Yii::ensureObject($stream, StreamInterface::class);
        }
        return $this->_stream;
    }
1078539
public function createInputStream(): InputStream {
		$this->ensureValid();
		try {
			return IoUtils::createSafeFileInputStream($this->fsPath);
		} catch (CouldNotAchieveFlockException $e) {
			return new FileResourceStream($this->fsPath, 'r');
		}
	}
138128
function(callback) {
    const contentStream = new stream.Writable();
    const data = [];

    contentStream._write = function(chunk) {
      callback(null, chunk.toString());
    };


    // here we can add the options in the future:
    // (options, context, gitRawCommitsOpts, parserOpts, writerOpts);
    const options = {
      preset: program.changelogpreset,
      releaseCount: program.releasecount,
    };
    changelog(options)
    // Use through() to handle multiple chunks which could be returned from changelog()
        .pipe(through({
          objectMode: true,
        }, function(chunk, enc, cb) {
          try {
            data.push(chunk);
          } catch (err) {
            setImmediate(function() {
              throw err;
            });
          }

          cb();
        }, function(cb) {
        // This function is called once ALL the object-chunks have been processed.
          data.push(null);

          cb(null, data.join('')); // Pass the data to the next stream processor
        }))
        .pipe(contentStream);
  }
213392
protected function createStream()
    {
        $stream = Psr7\stream_for();
        $this->writePartHeadersTo($stream);
        $stream->rewind();
        return $stream;
    }
825464
public function getStreamReader()
    {
        if ($this->streamReader !== null) {
            return $this->streamReader;
        }

        return $this->streamReader = new StreamReader($this);
    }