@actyx/pond 中文文档教程

发布于 3 年前 浏览 12 项目主页 更新于 2 年前

Actyx Pond Framework



一个开源的 Typescript/Javascript 框架,用于实现分布式状态机,这些状态机自动保持同步 一大群相互连接的设备。 Actyx Pond 需要在每台设备上运行 Actyx。

Actyx Pond 的主要特点是:

  • Distributed event-sourcing for great information replication facilities and declarative information consumption
  • Partition tolerance with an eventually consistent programming model for arbitrary business logic
  • Eventual consistency by using a state machine time-travel algorithm to agree on global state

该软件包构建于 Actyx SDK 之上。

Example usage

import { Pond, Tag, Fish, FishId } from '@actyx/pond'
(async () => {

    // Connect to the local Actyx process
    const pond = await Pond.default({
        appId: 'com.example.app',
        displayName: 'Example App',
        version: '1.0.0'
    })


    const chatTag = Tag<string>('ChatMessage');
    // A fish is a state machine
    const ChatFish: Fish<string[], string> = {
        fishId: FishId.of('chat', 'MyChatFish', 0),
        initialState: [],
        onEvent: (state, event) => {
            state.push(event);
            return state;
        },
        where: chatTag,
    };

    // Example event emission; this can actually
    // happen on any node running Actyx
    setInterval(() => {
        pond.emit(chatTag, 'a chat message')
    }, 2_000)

    // Observe time-travelling state machine
    pond.observe(ChatFish, (state) => {
        console.log(state)
    })

})()

Recommended VSCode plugins

  • ESLint for live source code linting

Actyx Pond Framework



An open-source Typescript/Javascript framework for implementing distributed state-machines which are automatically kept in sync across a swarm of interconnected devices. The Actyx Pond requires Actyx to be running on each device.

The key features of Actyx Pond are:

  • Distributed event-sourcing for great information replication facilities and declarative information consumption
  • Partition tolerance with an eventually consistent programming model for arbitrary business logic
  • Eventual consistency by using a state machine time-travel algorithm to agree on global state

This package builds on the Actyx SDK.

Example usage

import { Pond, Tag, Fish, FishId } from '@actyx/pond'
(async () => {

    // Connect to the local Actyx process
    const pond = await Pond.default({
        appId: 'com.example.app',
        displayName: 'Example App',
        version: '1.0.0'
    })


    const chatTag = Tag<string>('ChatMessage');
    // A fish is a state machine
    const ChatFish: Fish<string[], string> = {
        fishId: FishId.of('chat', 'MyChatFish', 0),
        initialState: [],
        onEvent: (state, event) => {
            state.push(event);
            return state;
        },
        where: chatTag,
    };

    // Example event emission; this can actually
    // happen on any node running Actyx
    setInterval(() => {
        pond.emit(chatTag, 'a chat message')
    }, 2_000)

    // Observe time-travelling state machine
    pond.observe(ChatFish, (state) => {
        console.log(state)
    })

})()

Recommended VSCode plugins

  • ESLint for live source code linting
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文