Home Reference Source Repository

js/Dispatch/DispatchQueue.js

  1. 'use strict'
  2.  
  3. import DispatchObject from './DispatchObject'
  4. //import __OS_dispatch_queue_attr from './__OS_dispatch_queue_attr'
  5. //import DispatchQoS from '.i/DispatchQoS'
  6. //import DispatchWorkItem from './DispatchWorkItem'
  7. //import DispatchGroup from './DispatchGroup'
  8. //import DispatchWorkItemFlags from './DispatchWorkItemFlags'
  9. //import DispatchTime from './DispatchTime'
  10. //import DispatchWallTime from './DispatchWallTime'
  11. //import DispatchSpecificKey from './DispatchSpecificKey'
  12.  
  13. const _AutoreleaseFrequency = {
  14. inherit: 0,
  15. never: 2,
  16. workItem: 1
  17. }
  18.  
  19. /**
  20. * @deprecated
  21. */
  22. const _GlobalQueuePriority = {
  23. background: 3,
  24. default: 1,
  25. high: 0,
  26. low: 2
  27. }
  28.  
  29. let _main = null
  30.  
  31. /**
  32. * DispatchQueue manages the execution of work items. Each work item submitted to a queue is processed on a pool of threads managed by the system.
  33. * @access public
  34. * @extends {DispatchObject}
  35. * @see https://developer.apple.com/documentation/dispatch/dispatchqueue
  36. */
  37. export default class DispatchQueue extends DispatchObject {
  38.  
  39. // Initializers
  40.  
  41. /**
  42. *
  43. * @access public
  44. * @param {string} label -
  45. * @param {DispatchQoS} qos -
  46. * @param {DispatchQueue.Attributes} attributes -
  47. * @param {DispatchQueue.AutoreleaseFrequency} autoreleaseFrequency -
  48. * @param {?DispatchQueue} target -
  49. * @constructor
  50. * @see https://developer.apple.com/documentation/dispatch/dispatchqueue/2300059-init
  51. */
  52. constructor(label, qos, attributes, autoreleaseFrequency, target) {
  53. super()
  54.  
  55. /**
  56. * @access private
  57. * @type {string}
  58. */
  59. this._label = label
  60.  
  61. /**
  62. * @access private
  63. * @type {DispatchQoS}
  64. */
  65. this._qos = qos
  66.  
  67. /**
  68. * @access private
  69. * @type {DispatchQueue.Attributes}
  70. */
  71. this._attributes = attributes
  72.  
  73. /**
  74. * @access private
  75. * @type {DispatchQueue.AutoreleaseFrequency}
  76. */
  77. this._target = target
  78. }
  79.  
  80.  
  81. /**
  82. * Creates a new dispatch queue to which blocks can be submitted.
  83. * @access public
  84. * @param {?UnsafePointer<Int8>} label - A string label to attach to the queue to uniquely identify it in debugging tools such as Instruments, sample, stackshots, and crash reports. Because applications, libraries, and frameworks can all create their own dispatch queues, a reverse-DNS naming style (com.example.myqueue) is recommended. This parameter is optional and can be NULL.
  85. * @param {?__OS_dispatch_queue_attr} attr - In macOS 10.7 and later or iOS 4.3 and later, specify DISPATCH_QUEUE_SERIAL (or NULL) to create a serial queue or specify DISPATCH_QUEUE_CONCURRENT to create a concurrent queue. In earlier versions, you must specify NULL for this parameter.
  86. * @returns {void}
  87. * @desc Blocks submitted to a serial queue are executed one at a time in FIFO order. Note, however, that blocks submitted to independent queues may be executed concurrently with respect to each other. Blocks submitted to a concurrent queue are dequeued in FIFO order but may run concurrently if resources are available to do so.If your app isn’t using ARC, you should call dispatch_release on a dispatch queue when it’s no longer needed. Any pending blocks submitted to a queue hold a reference to that queue, so the queue is not deallocated until all pending blocks have completed.
  88. * @see https://developer.apple.com/documentation/dispatch/dispatchqueue/1453030-init
  89. */
  90. init__label(label, attr) {
  91.  
  92. // Instance Properties
  93.  
  94. this._label = ''
  95. this._qos = null
  96. }
  97.  
  98. /**
  99. *
  100. * @access public
  101. * @param {?UnsafePointer<Int8>} label -
  102. * @param {?__OS_dispatch_queue_attr} attr -
  103. * @param {?DispatchQueue} target -
  104. * @returns {void}
  105. * @see https://developer.apple.com/documentation/dispatch/dispatchqueue/1642205-init
  106. */
  107. init__labelQueue(label, attr, target) {
  108.  
  109. // Instance Properties
  110.  
  111. this._label = ''
  112. this._qos = null
  113. }
  114.  
  115. // Instance Methods
  116.  
  117. /**
  118. *
  119. * @access public
  120. * @param {DispatchWorkItem} workItem -
  121. * @returns {void}
  122. * @see https://developer.apple.com/documentation/dispatch/dispatchqueue/1452870-sync
  123. */
  124. syncExecute(workItem) {
  125. }
  126.  
  127. /**
  128. *
  129. * @access public
  130. * @param {DispatchWorkItem} workItem -
  131. * @returns {void}
  132. * @see https://developer.apple.com/documentation/dispatch/dispatchqueue/2016103-async
  133. */
  134. asyncExecute(workItem) {
  135. }
  136.  
  137. /**
  138. *
  139. * @access public
  140. * @param {DispatchTime} deadline -
  141. * @param {DispatchWorkItem} execute -
  142. * @returns {void}
  143. * @see https://developer.apple.com/documentation/dispatch/dispatchqueue/2300020-asyncafter
  144. */
  145. asyncAfter(deadline, execute) {
  146. const delay = deadline - (Date.now())
  147. window.setTimeout(() => { execute() }, delay)
  148. }
  149.  
  150. /**
  151. *
  152. * @access public
  153. * @param {DispatchTime} deadline -
  154. * @param {DispatchQoS} qos -
  155. * @param {DispatchWorkItemFlags} flags -
  156. * @param {function(): void} work -
  157. * @returns {void}
  158. * @see https://developer.apple.com/documentation/dispatch/dispatchqueue/2300100-asyncafter
  159. */
  160. asyncAfterExecute(deadline, qos, flags, work) {
  161. }
  162.  
  163. /**
  164. *
  165. * @access public
  166. * @param {DispatchSpecificKey<T>} key -
  167. * @returns {?T} -
  168. * @see https://developer.apple.com/documentation/dispatch/dispatchqueue/1780751-getspecific
  169. */
  170. getSpecific(key) {
  171. return null
  172. }
  173.  
  174. /**
  175. *
  176. * @access public
  177. * @param {DispatchSpecificKey<T>} key -
  178. * @param {T} value -
  179. * @returns {void}
  180. * @see https://developer.apple.com/documentation/dispatch/dispatchqueue/1780629-setspecific
  181. */
  182. setSpecific(key, value) {
  183. }
  184.  
  185. /**
  186. *
  187. * @access public
  188. * @param {DispatchWorkItemFlags} flags -
  189. * @returns {void}
  190. * @throws {Error}
  191. * @see https://developer.apple.com/documentation/dispatch/dispatchqueue/2016077-sync
  192. */
  193. sync(flags) {
  194. }
  195.  
  196. // Instance Properties
  197. /**
  198. *
  199. * @type {string}
  200. * @desc
  201. * @see https://developer.apple.com/documentation/dispatch/dispatchqueue/1780825-label
  202. */
  203. get label() {
  204. return this._label
  205. }
  206. /**
  207. *
  208. * @type {DispatchQoS}
  209. * @desc
  210. * @see https://developer.apple.com/documentation/dispatch/dispatchqueue/1781008-qos
  211. */
  212. get qos() {
  213. return this._qos
  214. }
  215.  
  216. // Type Properties
  217. /**
  218. *
  219. * @type {DispatchQueue}
  220. * @desc
  221. * @see https://developer.apple.com/documentation/dispatch/dispatchqueue/1781006-main
  222. */
  223. static get main() {
  224. return _main
  225. }
  226.  
  227. // Type Methods
  228.  
  229. /**
  230. *
  231. * @access public
  232. * @param {number} iterations -
  233. * @param {function(arg1: number): void} work -
  234. * @returns {void}
  235. * @see https://developer.apple.com/documentation/dispatch/dispatchqueue/2016088-concurrentperform
  236. */
  237. static concurrentPerformExecute(iterations, work) {
  238. }
  239.  
  240. /**
  241. *
  242. * @deprecated
  243. * @access public
  244. * @param {DispatchQueue.GlobalQueuePriority} priority -
  245. * @returns {DispatchQueue} -
  246. * @see https://developer.apple.com/documentation/dispatch/dispatchqueue/2300070-global
  247. */
  248. static global(priority) {
  249. return null
  250. }
  251. }
  252.  
  253. //_main = new DispatchQueue("com.apple.main-thread", new DispatchQoS(DispatchQoS.userInteractive, 0))
  254. _main = new DispatchQueue('com.apple.main-thread', null)
  255.