Options
All
  • Public
  • Public/Protected
  • All
Menu

Represents an IAssignCancelable whose underlying cancelable reference can be swapped for another. It can be "chained" to another ChainedCancelable, forwarding all operations to it.

For most purposes it works like a MultiAssignCancelable:

  const s = ChainedCancelable.empty()
  s.update(c1) // sets the underlying cancelable to c1
  s.update(c2) // swaps the underlying cancelable to c2

  s.cancel() // also cancels c2
  s.update(c3) // also cancels c3, because s is already canceled

However it can also be linked to another ChainedCancelable reference, forwarding all requests to it:

  const source = ChainedCancelable.empty()
  const child1 = ChainedCancelable.empty()
  const child2 = ChainedCancelable.empty()

  // Hence forth forwards all operations on `child1` to `source`
  child1.chainTo(source)

  // Also forwarding all `child2` operations to `source`.
  // This happens because `child1` was linked to `source` first
  // but order matters, as `child2` will be linked directly
  // to `source` and not to `child1`, in order for `child1` to
  // be garbage collected if it goes out of scope ;-)
  child2.chainTo(child1)

  // Source will be updated with a new Cancelable ref
  child1.update(Cancelable.from(() => println("Cancelling (1)")))

  // Source will be updated with another Cancelable ref
  child2.update(Cancelable.from(() => println("Cancelling (2)")))

  source.cancel()
  //=> Cancelling (2)

This implementation is a special purpose IAssignCancelable, much like StackedCancelable, to be used in flatMap implementations that need it.

The problem that it solves in Funfix's codebase is that various flatMap implementations need to be memory safe. By "chaining" cancelable references, we allow the garbage collector to get rid of references created in a flatMap loop, the goal being to consume a constant amount of memory. Thus this implementation is used for the Future implementation.

If unsure about what to use, then you probably don't need ChainedCancelable. Use MultiAssignCancelable or SingleAssignCancelable for most purposes.

Hierarchy

  • ChainedCancelable

Implements

Index

Constructors

constructor

Methods

cancel

  • cancel(): void

chainTo

  • Chains this ChainedCancelable to another reference, such that all operations are forwarded to other.

    const source = ChainedCancelable.empty()
    const child1 = ChainedCancelable.empty()
    const child2 = ChainedCancelable.empty()
    
    // Hence forth forwards all operations on `child1` to `source`
    child1.chainTo(source)
    
    // Also forwarding all `child2` operations to `source`
    // (this happens because `child1` was linked to `source` first
    // but order matters ;-))
    child2.chainTo(child1)
    
    // Source will be updated with a new Cancelable ref
    child1.update( Cancelable.of(() => console.log("Cancelling (1)")) )
    
    // Source will be updated with another Cancelable ref
    child2.update( Cancelable.of (() => console.log("Cancelling (2)")) )
    
    source.cancel()
    //=> Cancelling (2)
    

    Parameters

    Returns this

clear

  • clear(): void
  • Clears the underlying reference, resetting it to a dummy reference.

    To be used for garbage collecting purposes.

    Returns void

isCanceled

  • isCanceled(): boolean

update

Static empty

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc