Skip to content

Instantly share code, notes, and snippets.

@ENvironmentSet
Last active October 29, 2018 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ENvironmentSet/0c8fde5510c6674694d3a6765c497a61 to your computer and use it in GitHub Desktop.
Save ENvironmentSet/0c8fde5510c6674694d3a6765c497a61 to your computer and use it in GitHub Desktop.
callbag korean readme

Origin

Callbag ๐Ÿ‘œ

๊ฐ€๋ฒผ์šด Observable ๊ณผ Iterable์„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•˜๋Š” ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ์ฝœ๋ฐฑ์„ ์œ„ํ•œ ํ‘œ์ค€

  • ์ตœ์†Œํ•œ์˜ ์˜ค๋ฒ„ํ—ค๋“œ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์ŠคํŠธ๋ฆผ, Iterable, Observable, AsyncIterable ๋“ฑ
  • Modular (๊ฐ๊ฐ์˜ ์˜คํผ๋ ˆ์ดํ„ฐ๋Š” ๊ทธ ์ž์ฒด๋กœ ํ•˜๋‚˜์˜ npm ํŒจํ‚ค์ง€์ž…๋‹ˆ๋‹ค.)
  • ๊ฐ€๋ฒผ์›€ (์ ์€ ๋ฉ”๋ชจ๋ฆฌ ํ• ๋‹น)
  • ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค, ๊ทธ์ € ํ‘œ์ค€์ผ ๋ฟ์ž…๋‹ˆ๋‹ค. (๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ฐพ๊ณ  ๊ณ„์‹ ๋‹ค๋ฉด callbag-basics์„ ํ™•์ธํ•˜์‹œ๊ฑฐ๋‚˜ ์œ„ํ‚ค๋ฅผ ํ™•์ธํ•ด ์ฃผ์„ธ์š”.)
  • ์—ฌ๋Ÿฌ๋ถ„๋งŒ์˜ ์œ ํ‹ธ๋ฆฌํ‹ฐ๋ฅผ ์ œ์ž‘ํ•˜๋Š” ๊ฒƒ์ด ๋งค์šฐ ์‰ฝ์Šต๋‹ˆ๋‹ค. ์œ ํ‹ธ๋ฆฌํ‹ฐ ์ œ์ž‘ํ•˜๋Š” ๋ฐฉ๋ฒ•

๊ทธ๋ฆฌ๊ณ  ์ด ๊ธ€๋“ค๋„ ์ฝ์–ด ๋ณด์„ธ์š”.

์š”์•ฝ

  • ๋ชจ๋“  producer๋Š” (type: number, payload?: any) => void ์ž…๋‹ˆ๋‹ค.
  • ๋ชจ๋“  consumer๋Š” (type: number, payload?: any) => void ์ž…๋‹ˆ๋‹ค.
  • type === 0 ์€ "start" ๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. (Observable ์˜ "subscribe" ์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.)
  • type === 1 ์€ "data" ๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. (Observable ์˜ "next" ์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค)
  • type === 2 ์€ "end" ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. (Subscriptions์˜ "unsubscribe" ์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.)

๋ช…์„ธ

(type: number, payload?: any) => void

์ •์˜

  • Callbag: (type: 0 | 1 | 2, payload?: any) => void ํƒ€์ž…์˜ ๊ฐ’.
  • Greet: if a callbag is called with 0 as the first argument, we say "the callbag is greeted", while the code which performed the call "greets the callbag"
  • Deliver: if a callbag is called with 1 as the first argument, we say "the callbag is delivered data", while the code which performed the call "delivers data to the callbag"
  • Terminate: if a callbag is called with 2 as the first argument, we say "the callbag is terminated", while the code which performed the call "terminates the callbag"
  • Source: a callbag which is expected to deliver data
  • Sink: a callbag which is expected to be delivered data

Protocol

The capitalized keywords used here follow IETF's RFC 2119.

Greets: (type: 0, cb: Callbag) => void

A callbag is greeted when the first argument is 0 and the second argument is another callbag (a function).

Handshake

When a source is greeted and given a sink as payload, the sink MUST be greeted back with a callbag payload that is either the source itself or another callbag (known as the "talkback"). In other words, greets are mutual. Reciprocal greeting is called a handshake.

Termination: (type: 2, err?: any) => void

A callbag is terminated when the first argument is 2 and the second argument is either undefined (signalling termination due to success) or any truthy value (signalling termination due to failure).

After the handshake, the source MAY terminate the sink. Alternatively, the sink MAY terminate the source after the handshake has occurred. If the source terminates the sink, then the sink SHOULD NOT terminate the source, and vice-versa. In other words, termination SHOULD NOT be mutual.

Data delivery (type: 1, data: any) => void

Amount of deliveries:

  • A callbag (either sink or source) MAY be delivered data, once or multiple times

Window of valid deliveries:

  • A callbag MUST NOT be delivered data before it has been greeted
  • A callbag MUST NOT be delivered data after it has been terminated
  • A sink MUST NOT be delivered data after it terminates its source

Reserved codes

A callbag SHOULD NOT be called with any of these numbers as the first argument: 3, 4, 5, 6, 7, 8, 9. Those are called reserved codes. A callbag MAY be called with codes other than those in the range [0-9], but this specification makes no claims in those cases.

Legal

This project is offered to the Public Domain in order to allow free use by interested parties who want to create compatible implementations. For details see COPYING and CopyrightWaivers.txt.

CC0
To the extent possible under law, Callbag Standard Special Interest Group has waived all copyright and related or neighboring rights to Callbag Standard. This work is published from: Finland.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment