../libs/loadable/loadable

  Source   Edit

A LoadableResource is similar to a JS promise or a Future, except that you can store it to load it any number of times, and instead of providing an object, you get a pointer, a length, and a function to tell it you're done with it. You cannot have more than one callback, but you can obtain the results of many with loadAll or get a callback when many are done with allDone

TODO IMPORTANT: probably not thread safe, call all functions in the same thread
if you use loadAll and allDone

TODO: investigate the use of signals instead of callbacks

Types

Fetch = ref object of LoadableResource
  custom: pointer
  Source   Edit
LoadableResource = ref object of RootObj
  status: LoadableResourceStatus
  start_func: proc (self: LoadableResource) {.closure.}
  onload_func: proc (ok: bool; err: string; data: SliceMem[byte]) {.closure.}
  cancel_func: proc () {.closure.}
  str*: proc (): string
  use_threads: bool
  Source   Edit
LoadableResourceStatus = enum
  NotStarted, Started, Finished, Error
  Source   Edit

Procs

proc cancel[T: LoadableResource](self: T)
  Source   Edit
func escapeUTF8(s: string): string {....raises: [], tags: [].}
  Source   Edit
proc loadUri(uri: string; onload_func: proc (ok: bool; err: string;
    data: SliceMem[byte]) = nil; range = (-1, -1); auto_start = true;
             use_threads = true): Fetch {.discardable, ...raises: [Exception],
    tags: [RootEffect].}
  Source   Edit
proc newLoadableResource[T: LoadableResource](
    start: proc (self: LoadableResource); str: proc (): string = nil;
    use_threads = false): T
  Source   Edit
proc onload=[T: LoadableResource](self: T; onload_func: proc (ok: bool;
    err: string; data: SliceMem[byte]))
  Source   Edit
proc onload[T: LoadableResource](self: T; ok: bool; err: string;
                                 data = SliceMem[byte]())
  Source   Edit
proc start[T: LoadableResource](self: T)
  Source   Edit
proc terminateLoadableWorkerThreads() {....raises: [], tags: [].}
  Source   Edit
proc updateLoadableWorkerThreads() {....raises: [ValueError, Exception],
                                     tags: [RootEffect].}
  Source   Edit