퓨처와 프로미스
컴퓨터 과학에서 퓨처(future), 프로미스(promise), 딜레이(delay), 디퍼드(deferred)는 일부 병행 프로그래밍 언어에서 프로그램 실행을 동기화하려고 쓰는 구조체다. 프록시 역할을 하는 객체로 설명되며 값의 연산이 아직 이루어지지 않은 상태이므로 결과는 미리 알 수 없다.
프로미스(promise)라는 용어는 1976년 대니얼 P. 프리드먼과 데이비드 와이즈가 제안하였으며,[1] 피터 히버드는 eventual로 명명하였다.[2] 일부 비슷한 개념인 퓨처(future)는 1977년 헨리 베이커와 칼 히위트의 논문에 등장하였다.[3]
퓨처, 프로미스, 딜레이, 디퍼드라는 용어는 종종 번갈아 사용되지만 퓨처와 프로미스 사이에는 이용 면에서 일부 차이가 있다. 퓨처는 변수의 읽기 전용 플레이스홀더인 반면 프로미스는 미래의 값을 저장하는, 쓰기가 가능한 단일 할당 컨테이너이다.[4] 퓨처는 어느 특정 프로미스가 값을 설정할지를 지정하지 않고 정의할 수 있으며 각기 다른 잠재적인 프로미스들이 주어진 퓨처의 값을 설정할 수 있지만 주어진 퓨처에 대해 오직 한 번만 수행이 가능하다. 그 밖의 경우 퓨처와 프로미스는 함께 만들어지며 서로 연결된다. 즉, 퓨처는 값이고 프로미스는 값을 설정하는 함수, 특히 비동기 함수(프로미스)의 반환값(퓨처)을 의미한다. 퓨처의 값을 설정하는 것은 바인딩(binding), 풀필링(fulfilling), 리졸빙(resolving)으로 부른다.
구현체 목록
일부 프로그래밍 언어들은 퓨처, 프로미스, 병행 논리 변수, 데이터플로 변수, l-var을 지원하며 이는 직접 언어 지원을 통해서나 표준 라이브러리를 통해 제공된다.
프로그래밍 언어에 따른 퓨처와 프로미스 관련 개념 목록
- ABCL/f[5]
- Alice ML
- AmbientTalk (including first-class resolvers and read-only promises)
- C++, starting with C++11: std::future and std::promise
- μC++
- Compositional C++
- Crystal (programming language)
- Dart (with Future/Completer classes[6] and the keywords await and async[7])
- Elm (programming language) via the Task module[8]
- Glasgow 하스켈 (I-vars and M-vars only)
- Id (I-vars and M-vars only)
- Io[9]
- 자바 via
java.util.concurrent.Future
orjava.util.concurrent.CompletableFuture
- 자바스크립트 (limited, as of ECMA스크립트 6)
- Lucid (dataflow only)
- Some Lisps
- 클로저 (프로그래밍 언어)[10]
- MultiLisp
- .NET via Tasks
- Nim
- Oxygene
- Oz version 3[13]
- 파이썬 concurrent.futures, since 3.2,[14] as proposed by the PEP 3148, and Python 3.5 added async and await[15]
- R (promises for lazy evaluation, still single threaded)
- Racket[16]
- Raku[17]
- Scala via scala.concurrent package
- Scheme
- 스퀵 스몰토크
- Strand
- Swift (only via third-party libraries)
- Visual Basic 11 (via the keywords Async and Await)[12]
프로미스 파이프라이닝을 지원하는 언어:
- E
- 줄
비표준 라이브러리 기반 퓨처 구현체 목록
- For 커먼 리스프:
- For C++:
- For C# and other .NET languages: The Parallel Extensions library
- For Groovy: GPars[29]
- For 자바스크립트:
- Cujo.js'[30] when.js[31] provides promises conforming to the Promises/A+[32] 1.1 specification
- The Dojo Toolkit supplies promises[33] and Twisted style deferreds
- MochiKit[34] inspired by Twisted's Deferreds
- jQuery's Deferred Object is based on the CommonJS Promises/A design.
- AngularJS[35]
- node-promise[36]
- Q, by Kris Kowal, conforms to Promises/A+ 1.1[37]
- RSVP.js, conforms to Promises/A+ 1.1[38]
- YUI's[39] promise class[40] conforms to the Promises/A+ 1.0 specification.
- Bluebird, by Petka Antonov[41]
- The Closure Library's promise package conforms to the Promises/A+ specification.
- See Promise/A+'s list for more implementations based on the Promise/A+ design.
- For 자바:
- For Lua:
- The cqueues [1] module contains a Promise API.
- For 오브젝티브-C: MAFuture,[44][45] RXPromise,[46] ObjC-CollapsingFutures,[47] PromiseKit,[48] objc-promise,[49] OAPromise,[50]
- For OCaml: Lazy module implements lazy explicit futures[51]
- For 펄: Future,[52] Promises,[53] Reflex,[54] and Promise::ES6[55]
- For PHP: React/Promise[56]
- For 파이썬:
- For R:
- For Ruby:
- For Rust:
- futures-rs[66]
- For Scala:
- Twitter's util library[67]
- For Swift:
- Async framework, implements C#-style
async
/non-blockingawait
[68] - FutureKit,[69] implements a version for Apple GCD[70]
- FutureLib, pure Swift 2 library implementing Scala-style futures and promises with TPL-style cancellation[71]
- Deferred, pure Swift library inspired by OCaml's Deferred[72]
- BrightFutures[73]
- Async framework, implements C#-style
- For Tcl: tcl-promise[74]
같이 보기
각주
- ↑ Friedman, Daniel; David Wise (1976). 《The Impact of Applicative Programming on Multiprocessing》. International Conference on Parallel Processing. 263–272쪽.
- ↑ Hibbard, Peter (1976). 《Parallel Processing Facilities》. New Directions in Algorithmic Languages, (ed.) Stephen A. Schuman, IRIA, 1976.
- ↑ Henry Baker; Carl Hewitt (August 1977). 《The Incremental Garbage Collection of Processes》. Proceedings of the Symposium on Artificial Intelligence Programming Languages. ACM SIGPLAN Notices 12, 8. 55–59쪽. 2008년 7월 4일에 원본 문서에서 보존된 문서. 2020년 8월 13일에 확인함.
- ↑ "SIP-14 – Futures and Promises 보관됨 2019-07-05 - 웨이백 머신"
- ↑ Kenjiro Taura; Satoshi Matsuoka; Akinori Yonezawa (1994). 〈ABCL/f: A Future-Based Polymorphic Typed Concurrent Object-Oriented Language – Its Design and Implementation.〉. 《In Proceedings of the DIMACS workshop on Specification of Parallel Algorithms, number 18 in Dimacs Series in Discrete Mathematics and Theoretical Computer Science》. American Mathematical Society. 275–292쪽. CiteSeerX 10.1.1.23.1161.
- ↑ “Dart SDK dart async Completer”.
- ↑ Gilad Bracha (October 2014). “Dart Language Asynchrony Support: Phase 1”.
- ↑ “Task”.
- ↑ Steve Dekorte (2005). “Io, The Programming Language”.
- ↑ Rich Hickey (2009). “changes.txt at 1.1.x from richhickey's clojure”.
- ↑ “Async in 4.5: Worth the Await – .NET Blog – Site Home – MSDN Blogs”. Blogs.msdn.com. 2012년 4월 7일에 원본 문서에서 보존된 문서. 2014년 5월 13일에 확인함.
- ↑ 가 나 “Asynchronous Programming with Async and Await (C# and Visual Basic)”. Msdn.microsoft.com. 2014년 5월 13일에 확인함.
- ↑ Seif Haridi; Nils Franzen. “Tutorial of Oz”. Mozart Global User Library. 2011년 5월 14일에 원본 문서에서 보존된 문서. 2011년 4월 12일에 확인함.
- ↑ Python 3.2 Release
- ↑ Python 3.5 Release
- ↑ “Parallelism with Futures”. PLT. 2012년 3월 2일에 확인함.
- ↑ Promise class in Perl 6
- ↑ Common Lisp Blackbird
- ↑ Common Lisp Eager Future2
- ↑ Lisp in parallel – A parallel programming library for Common Lisp
- ↑ Common Lisp PCall
- ↑ “Chapter 30. Thread 4.0.0”. 2013년 6월 26일에 확인함.
- ↑ “Dlib C++ Library #thread_pool”. 2013년 6월 26일에 확인함.
- ↑ “QtCore 5.0: QFuture Class”. Qt Project. 2013년 6월 1일에 원본 문서에서 보존된 문서. 2013년 6월 26일에 확인함.
- ↑ “Seastar”. Seastar project. 2016년 8월 22일에 확인함.
- ↑ “GitHub – facebook/folly: An open-source C++ library developed and used at Facebook.”. 2019년 1월 8일.
- ↑ “Threads Slides of POCO” (PDF).
- ↑ “HPX”. 2019년 2월 10일.
- ↑ Groovy GPars 보관됨 12 1월 2013 - 웨이백 머신
- ↑ “Cujo.js”. 2012년 3월 17일에 원본 문서에서 보존된 문서. 2021년 6월 12일에 확인함.
- ↑ JavaScript when.js
- ↑ Promises/A+ specification
- ↑ promises
- ↑ JavaScript MochKit.Async
- ↑ JavaScript Angularjs
- ↑ JavaScript node-promise
- ↑ “JavaScript Q”. 2018년 12월 31일에 원본 문서에서 보존된 문서. 2020년 8월 13일에 확인함.
- ↑ JavaScript RSVP.js
- ↑ YUI JavaScript class library
- ↑ YUI JavaScript promise class
- ↑ JavaScript Bluebird
- ↑ Java JDeferred
- ↑ Java ParSeq
- ↑ Objective-C MAFuture GitHub
- ↑ Objective-C MAFuture mikeash.com
- ↑ Objective-C RXPromise
- ↑ ObjC-CollapsingFutures
- ↑ Objective-C PromiseKit
- ↑ Objective-C objc-promise
- ↑ Objective-C OAPromise
- ↑ OCaml Lazy
- ↑ Perl Future
- ↑ Perl Promises
- ↑ Perl Reflex
- ↑ Perl Promise::ES6
- ↑ PHP React/Promise
- ↑ Python built-in implementation
- ↑ pythonfutures
- ↑ “Twisted Deferreds”. 2020년 8월 6일에 원본 문서에서 보존된 문서. 2020년 8월 13일에 확인함.
- ↑ R package future
- ↑ future
- ↑ Ruby Promise gem
- ↑ Ruby libuv
- ↑ “Ruby Celluloid gem”. 2013년 5월 8일에 원본 문서에서 보존된 문서. 2021년 3월 15일에 확인함.
- ↑ Ruby future-resource
- ↑ futures-rs crate
- ↑ Twitter's util library
- ↑ “Swift Async”. 2018년 12월 31일에 원본 문서에서 보존된 문서. 2020년 8월 13일에 확인함.
- ↑ Swift FutureKit
- ↑ Swift Apple GCD
- ↑ Swift FutureLib
- ↑ bignerdranch/Deferred
- ↑ Thomvis/BrightFutures
- ↑ tcl-promise
외부 링크
- Concurrency patterns presentation given at scaleconf
- Future Value and Promise Pipelining at the en:Portland Pattern Repository
- Easy Threading with Futures 보관됨 2007-12-10 - 웨이백 머신 in 파이썬