All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.cloudshiftdev.awscdk.services.lambda.IEventSource.kt Maven / Gradle / Ivy

The newest version!
@file:Suppress("RedundantVisibilityModifier","RedundantUnitReturnType","RemoveRedundantQualifierName","unused","UnusedImport","ClassName","REDUNDANT_PROJECTION","DEPRECATION")

package io.cloudshiftdev.awscdk.services.lambda

import io.cloudshiftdev.awscdk.common.CdkObject
import io.cloudshiftdev.awscdk.common.CdkObjectWrappers

/**
 * An abstract class which represents an AWS Lambda event source.
 */
public interface IEventSource {
  /**
   * Called by `lambda.addEventSource` to allow the event source to bind to this function.
   *
   * @param target That lambda function to bind to. 
   */
  public fun bind(target: IFunction)

  private class Wrapper(
    cdkObject: software.amazon.awscdk.services.lambda.IEventSource,
  ) : CdkObject(cdkObject),
      IEventSource {
    /**
     * Called by `lambda.addEventSource` to allow the event source to bind to this function.
     *
     * @param target That lambda function to bind to. 
     */
    override fun bind(target: IFunction) {
      unwrap(this).bind(target.let(IFunction.Companion::unwrap))
    }
  }

  public companion object {
    internal fun wrap(cdkObject: software.amazon.awscdk.services.lambda.IEventSource): IEventSource
        = CdkObjectWrappers.wrap(cdkObject) as? IEventSource ?: Wrapper(cdkObject)

    internal fun unwrap(wrapped: IEventSource): software.amazon.awscdk.services.lambda.IEventSource
        = (wrapped as CdkObject).cdkObject as software.amazon.awscdk.services.lambda.IEventSource
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy