外观
obs
原文: https://finproducts.atlassian.net/wiki/spaces/JIDD3/pages/34793390550/FIN+5.3.1+obs 中文整理基于 FIN 5.3.1
导读: 可观察数据流框架
以下为 API 参考,保留英文以便对照源码;目录已列出(英文标题便于检索);概述已尽量中译。
目录(导读)
- mixins
- classes
- Slot Details
- hasSubscriptions
- name
- onSubscribe
- onUnsubscribe
- subscribe
- subscriptions
- unsubscribe
- unsubscribeAll
- subType
- ts
- type
- actor
- meta
- filter
- include
- make
- config
- isSubscribed
- isUnsubscribed
- observable
- observer
- send
- sync
- toStr
概述(中译)
抽象常量类 Observable : Obj
Observable 是异步数据流的主题。
注意:此 API 可能会发生变化
方法
插槽详情
API 正文(英文)
hasSubscriptions
Bool hasSubscriptions()
Does this observer have any active subscriptions
name
abstract Str name()
Return the name of this observable. This name must match up with the the observe def subtype name
onSubscribe
protected virtual Subscription onSubscribe(Observer observer, Dict config)
Callback when new observer is subscribing. Subclasses can check the config and return their own subscription subclass. This callback can be from any thread, so must be thread safe.
onUnsubscribe
protected virtual Void onUnsubscribe(Subscription s)
Callback after an observer is unsubscribed. This callback can be from any thread, so must be thread safe.
subscribe
Subscription subscribe(Observer observer, Dict config)
Subscribe an observer actor to this this observables data stream
subscriptions
Subscription[] subscriptions()
List the active subscriptions
unsubscribe
Void unsubscribe(Subscription s)
Unsubscribe a current subscription
unsubscribeAll
Void unsubscribeAll()
Unsubscribe all subscriptions
Observation
const mixin Observation : Dict
Observation is base class for all observable data items
NOTE: this API is subject to change
Methods
| subType | Subtype name if available which is specific to the observable type |
| ts | Timestamp for the event |
| type | Type name which matches Observable.name and the def name |
Slot Details
subType
abstract Str? subType()
Subtype name if available which is specific to the observable type
ts
abstract DateTime ts()
Timestamp for the event
type
abstract Str type()
Type name which matches Observable.name and the def name
Observer
const mixin Observer
Observer is an actor which subscribes to an observable's data items
NOTE: this API is subject to change
Methods
| actor | Actor for observer |
| meta | Meta data for observer |
Slot Details
actor
abstract Actor actor()
Actor for observer
meta
abstract Dict meta()
Meta data for observer
RecSubscription
const class RecSubscription : Subscription
RecSubscription is used for obsRecs to handle filtering
NOTE: this API is subject to change
Constructors
| make | Constructor |
Fields
| filter | Filter is configured |
Methods
| include | Match the record against configured filter |
Slot Details
filter
const Filter? filter
Filter is configured
include
Bool include(Dict rec)
Match the record against configured filter
make
new make(Observable observable, Observer observer, Dict config)
Constructor
Subscription
const class Subscription : Obj
Subscription models an Observable to Observer binding
NOTE: this API is subject to change
Constructors
| make | Constructor |
Fields
| config | Configuration options for subscription |
| observable | Observable producing data items |
| observer | Subscribed observer consuming data items |
Methods
| isSubscribed | Return if this subscription is still active |
| isUnsubscribed | Return if this subscription has been cancelled |
| send | Send observation message to observer actor |
| sync | Send sync message to observer actor |
| toStr | Debug string |
| unsubscribe | Convenience for Observable.unsubscribe(this) |
Slot Details
config
const Dict config
Configuration options for subscription
isSubscribed
Bool isSubscribed()
Return if this subscription is still active
isUnsubscribed
Bool isUnsubscribed()
Return if this subscription has been cancelled
make
new make(Observable observable, Observer observer, Dict config)
Constructor
observable
const Observable observable
Observable producing data items
observer
const Observer observer
Subscribed observer consuming data items
send
Future send(Observation msg)
Send observation message to observer actor
sync
Future sync()
Send sync message to observer actor
toStr
override Str toStr()
Debug string
unsubscribe
Void unsubscribe()
Convenience for Observable.unsubscribe(this)