All Projects → kdex → Ws Promise Client

kdex / Ws Promise Client

Licence: gpl-3.0
PROJECT MOVED: https://github.com/kdex/ws-promise

Programming Languages

javascript
184084 projects - #8 most used programming language
ecmascript
72 projects

Projects that are alternatives of or similar to Ws Promise Client

Wx Promise Pro
✨强大、优雅的微信小程序异步库🚀
Stars: ✭ 762 (+12600%)
Mutual labels:  async, promise, await
Await Of
await wrapper for easier errors handling without try-catch
Stars: ✭ 240 (+3900%)
Mutual labels:  async, promise, await
Breeze
Javascript async flow control manager
Stars: ✭ 38 (+533.33%)
Mutual labels:  async, promise, await
Datakernel
Alternative Java platform, built from the ground up - with its own async I/O core and DI. Ultra high-performance, simple and minimalistic - redefines server-side programming, web-development and highload!
Stars: ✭ 87 (+1350%)
Mutual labels:  rpc, async, promise
P Map
Map over promises concurrently
Stars: ✭ 639 (+10550%)
Mutual labels:  async, promise, await
P Iteration
Utilities that make array iteration easy when using async/await or Promises
Stars: ✭ 337 (+5516.67%)
Mutual labels:  async, promise, await
Emacs Async Await
Async/Await for Emacs
Stars: ✭ 47 (+683.33%)
Mutual labels:  async, promise, await
Python Binance Chain
Binance Chain Exchange API python implementation for automated trading
Stars: ✭ 96 (+1500%)
Mutual labels:  rpc, websocket, client
Jstp
Fast RPC for browser and Node.js based on TCP, WebSocket, and MDSF
Stars: ✭ 132 (+2100%)
Mutual labels:  rpc, websocket, client
ws-promise
A tiny, Promise-based WebSocket protocol allowing request-response usage in ECMAScript
Stars: ✭ 20 (+233.33%)
Mutual labels:  promise, rpc, await
Awaitkit
The ES8 Async/Await control flow for Swift
Stars: ✭ 709 (+11716.67%)
Mutual labels:  async, promise, await
Websocket As Promised
A Promise-based API for WebSockets
Stars: ✭ 485 (+7983.33%)
Mutual labels:  promise, websocket
Kneden
Transpile ES2017 async/await to vanilla ES6 Promise chains: a Babel plugin
Stars: ✭ 517 (+8516.67%)
Mutual labels:  async, promise
Cppserver
Ultra fast and low latency asynchronous socket server & client C++ library with support TCP, SSL, UDP, HTTP, HTTPS, WebSocket protocols and 10K connections problem solution
Stars: ✭ 528 (+8700%)
Mutual labels:  async, websocket
React Hooks Async
React custom hooks for async functions with abortability and composability
Stars: ✭ 459 (+7550%)
Mutual labels:  async, promise
Getty
a netty like asynchronous network I/O library based on tcp/udp/websocket; a bidirectional RPC framework based on JSON/Protobuf; a microservice framework based on zookeeper/etcd
Stars: ✭ 532 (+8766.67%)
Mutual labels:  rpc, websocket
Netcoreserver
Ultra fast and low latency asynchronous socket server & client C# .NET Core library with support TCP, SSL, UDP, HTTP, HTTPS, WebSocket protocols and 10K connections problem solution
Stars: ✭ 799 (+13216.67%)
Mutual labels:  async, websocket
Grain
grain是一个极简的、组件式的RPC框架,灵活且适合渐进学习,可与任何框架整合。同时包含(系统通用多线程模型与消息通讯 || 多对多关系的分布式锁 || 基于Servlet的HTTP框架 || 基于系统通用多线程模型的Websocket框架 || 支持行级锁的多线程锁 )等组件,按需选择组件,不绑架开发者。
Stars: ✭ 577 (+9516.67%)
Mutual labels:  rpc, websocket
Micro Router
🚉 A tiny and functional router for Zeit's Micro
Stars: ✭ 621 (+10250%)
Mutual labels:  async, await
Happypandax
A cross-platform server and client application for managing and reading manga and doujinshi
Stars: ✭ 432 (+7100%)
Mutual labels:  rpc, client

Project moved

This project has moved here. This repository is deprecated.

ws-promise-client

ws-promise-client is a tiny framework that builds a request-response model onto HTML5 WebSockets using ES2015 Promises. You can use this with ES2017's await/async to simplify your WebSocket API. Both browsers and node.js are supported.

The official server to use with this client can be found at kdex/ws-promise-server. This client supports any server that adheres to the RPC protocol.

Getting started

Your WebSocket code could roughly map to something like this:

import Client from "ws-promise-client";
const client = new Client("ws://localhost:8080");
(async () => {
	/* The client connects (it will, by default, also automatically reconnect) */
	await client.open();
	/* Both parties can have an array of return values in `reply` */
	const [result] = await client.send({
		instruction: "multiply",
		args: [1, 2, 3]
	});
	/* Prints `6` */
	console.log(result);
})();

This code creates a client, connects to a server, then sends a message and receives the according reply without the need for setting up any kind of explicit callback or message IDs.

API reference

Client.constructor(url, protocols, options)

Constructs a new ws-promise-client connecting to the url supporting the subprotocols protocols. The options argument is an optional object with the following keys:

autoReconnect (default: true)

Boolean property that determines whether to automatically reconnect to the server in case of connection losses, and also when the initial connect is unsuccessful.

reconnectionFactor (default: 1.2)

Numeric property that determines which factor to multiply the waiting time with after each reconnection try.

reconnectionMinimum (default: 2000)

Numeric property that determines the minimum amount of milliseconds to wait before reconnecting. Note that the initial reconnect will be tried immediately after a connection loss, regardless of this amount.

rpcOptions

An option object that will be passed to the constructor of ws-rpc-client.

Client.prototype.open()

Opens the websocket connection and returns a promise that resolves once the connection is open.

Client.prototype.close()

Closes the websocket connection and returns a promise that resolves once the connection is closed.

Client.prototype.reconnect(newWaitingTime)

Reconnects to the server and returns a Promise that resolves once the connection is (re-)opened. Before reconnecting for the first time, there will be a delay of newWaitingTime. If newWaitingTime is not provided, reconnectionMinimum is used.

Client.prototype.send(payload)

Sends payload to the server and returns a Promise that that resolves when the server's reply has been received. For more information on which keys are needed in payload, see the protocol (which also defines the send method).

Events

The following standard WebSocket client events are supported:

  • close
  • error
  • message
  • open

The client also provides these additional events:

  • connectionFailed
  • reconnect
  • [instruction]

The [instruction] event is a custom event that fires once an instruction with the name of instruction is received. For example, if the server sends a message with an instruction of showMenu, the client will call its onShowMenu method (if available) with the arguments that the server has put in the payload's args property.

All events can either be handled by providing a handler method named on[Event] (see example above) or by registering an event listeners via on(event, handler).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].