本文整理匯總了TypeScript中sodiumjs.StreamSink類的典型用法代碼示例。如果您正苦於以下問題:TypeScript StreamSink類的具體用法?TypeScript StreamSink怎麽用?TypeScript StreamSink使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了StreamSink類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
import { StreamSink } from 'sodiumjs'
const s1 = new StreamSink<string>()
const s2 = new StreamSink<string>()
const d1 = s1.orElse(s2).hold('init1')
d1.listen(v => console.log(`*** d1 = ${v}`))
s1.send('s1-1')
s2.send('s2-1')
s1.send('s1-2')
s1.send('s1-3')
s2.send('s2-2')
示例2:
interface Message {
type: string
body: string
}
import { StreamSink } from 'sodiumjs'
const src = new StreamSink<Message>()
const category = src.filter(d => d.type == 'category').map(m => m.body)
category.listen(c => console.log(`category = ${c}`))
const value = src.filter(d => d.type == 'value').map(m => m.body)
value.listen(v => console.log(`value = ${v}`))
value.snapshot(category.hold(''), (v, c) => [c, v])
.listen(d => console.log(`*** ${d}`))
src.send({type: 'category', body: 'type1'})
src.send({type: 'value', body: '1'})
src.send({type: 'category', body: 'type2'})
src.send({type: 'value', body: '2'})
src.send({type: 'invalid', body: 'test'})
src.send({type: 'value', body: '3'})
示例3:
Transaction.run<void>(() => {
s1.send(10)
s2.send(9)
})